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

Tanner Clary edited comment on CALCITE-5591 at 5/30/23 3:21 PM:
----------------------------------------------------------------

[~FrankZou] That makes sense. 

For overflow, my early attempt looks something like this: 

{{private static boolean isOverflow(BigDecimal b0) (
    return b0.compareTo(BigDecimal.valueOf(Long.MIN_VALUE)) < 0 ||
              b0.compareTo(BigDecimal.valueOf(Long.MAX_VALUE)) > 0;
  )}}

This is a helper that could be used in {{SqlFunctions}}. Thoughts?


was (Author: JIRAUSER298151):
[~FrankZou] That makes sense. 

For overflow, my early attempt looks something like this: 

{{ 
 private static boolean isOverflow(BigDecimal b0) (
    return b0.compareTo(BigDecimal.valueOf(Long.MIN_VALUE)) < 0 ||
              b0.compareTo(BigDecimal.valueOf(Long.MAX_VALUE)) > 0;
  )
}}

This is a helper that could be used in {{SqlFunctions}}. Thoughts?

> Implement BigQuery functions SAFE_ADD, SAFE_SUBTRACT, SAFE_MULTIPLY, 
> SAFE_DIVIDE and SAFE_NEGATE
> ------------------------------------------------------------------------------------------------
>
>                 Key: CALCITE-5591
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5591
>             Project: Calcite
>          Issue Type: New Feature
>            Reporter: Dan Zou
>            Assignee: Dan Zou
>            Priority: Major
>
> Add support for SAFE_ADD, SAFE_SUBTRACT, SAFE_MULTIPLY, SAFE_DIVIDE and 
> SAFE_NEGATE in BigQuery.
> Function description:
> * SAFE_ADD: Equivalent to the addition operator '+', but returns NULL if 
> overflow occurs.
> * SAFE_SUBTRACT: Returns the result of Y subtracted from X. Equivalent to the 
> subtraction operator '-', but returns NULL if overflow occurs.
> * SAFE_MULTIPLY: Equivalent to the multiplication operator '*', but returns 
> NULL if overflow occurs.
> * SAFE_DIVIDE: Equivalent to the division operator '/ ', but returns NULL if 
> an error occurs, such as a division by zero error.
> * SAFE_NEGATE: Equivalent to the unary minus operator '-', but returns NULL 
> if overflow occurs.
> See more details in [BigQuery 
> Doc|https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#safe_divide]



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

Reply via email to