You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2023/06/07 23:25:00 UTC

[jira] [Commented] (CALCITE-5766) Implement SAFE_NEGATE function (enabled for BigQuery)

    [ https://issues.apache.org/jira/browse/CALCITE-5766?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17730308#comment-17730308 ] 

Julian Hyde commented on CALCITE-5766:
--------------------------------------

I think there are a lot of scenarios where multiply can overflow, especially when we are dealing with floating point numbers. We have several data types (TINYINT, INTEGER, SMALLINT, BIGINT, REAL, DOUBLE, DECIMAL) and the floating point types have special values like -inf, inf, NaN, -0. Therefore I would expect there to be dozens of tests for this.

I'm not convinced that your simple check for overflow works. As I said in an earlier PR comment, I would be inclined to use special functions in {{java.math.Math}}. I could be convinced of your approach if there are lots of tests.

Maybe you can search for a set of corner cases that test overflow for integers and FP types?

> Implement SAFE_NEGATE function (enabled for BigQuery)
> -----------------------------------------------------
>
>                 Key: CALCITE-5766
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5766
>             Project: Calcite
>          Issue Type: Sub-task
>            Reporter: Tanner Clary
>            Assignee: Tanner Clary
>            Priority: Major
>              Labels: pull-request-available
>
> Add support for SAFE_NEGATE in BigQuery.
> SAFE_NEGATE: Equivalent to the unary minus operator (-), but returns NULL if overflow occurs.
> Example #1: {{SELECT SAFE_NEGATE(3)}} would return {{-3}}.
> Example #2: {{SELECT SAFE_NEGATE(-9223372036854775808)}} would return {{NULL}} because of overflow.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)