[ 
https://issues.apache.org/jira/browse/CALCITE-5735?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Tanner Clary updated CALCITE-5735:
----------------------------------
    Description: 
BigQuery offers the {{SAFE_MULTIPLY(value1, value2)}} function which returns 
the result of {{value1}} * {{value2}}. If overflow occurs, null is returned.

The correct return type may be inferred according to the [BigQuery 
docs|https://cloud.google.com/bigquery/docs/reference/standard-sql/mathematical_functions#safe_multiply].
 

BigQuery treats all integer types as aliases for {{BIGINT}} (which BigQuery 
calls {{INT64}}. Therefore, all integer types (and the result of their 
multiplication) should be treated as {{BIGINT}}. This means, for example, 
multiplying two {{TINYINT}} that would cause {{TINYINT}} overflow, would be 
okay as long as the result does not also cause {{BIGINT}} overflow. {{BIGINT}} 
translates to Java's {{LONG}} whose bounds are used to determine whether 
overflow has occurred.

BigQuery also supports {{Decimal}} and {{BigDecimal}} types, which maps to 
Calcite's {{DECIMAL}} type. Their overflow is determined using their precision 
and scale, and if they exceed BigQuery's limits, then overflow has occurred.

BigQuery's {{FLOAT64}} maps to Java's {{DOUBLE}} and it's {{MAX_VALUE}} and 
{{MIN_VALUE}} are used to determine whether overflow has occurred. 

  was:
Add support for SAFE_MULTIPLY in BigQuery.
SAFE_MULTIPLY: Equivalent to the multiplication operator '*', but returns NULL 
if overflow occurs.

Example #1: {{SELECT SAFE_MULTIPLY(3, 4)}} would return {{12}}.
Example #2: {{SELECT SAFE_MULTIPLY(2^63, 2)}} would return {{NULL}} because of 
overflow.


> Implement SAFE_MULTIPLY function (enabled for BigQuery)
> -------------------------------------------------------
>
>                 Key: CALCITE-5735
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5735
>             Project: Calcite
>          Issue Type: Sub-task
>            Reporter: Tanner Clary
>            Assignee: Tanner Clary
>            Priority: Major
>              Labels: pull-request-available
>
> BigQuery offers the {{SAFE_MULTIPLY(value1, value2)}} function which returns 
> the result of {{value1}} * {{value2}}. If overflow occurs, null is returned.
> The correct return type may be inferred according to the [BigQuery 
> docs|https://cloud.google.com/bigquery/docs/reference/standard-sql/mathematical_functions#safe_multiply].
>  
> BigQuery treats all integer types as aliases for {{BIGINT}} (which BigQuery 
> calls {{INT64}}. Therefore, all integer types (and the result of their 
> multiplication) should be treated as {{BIGINT}}. This means, for example, 
> multiplying two {{TINYINT}} that would cause {{TINYINT}} overflow, would be 
> okay as long as the result does not also cause {{BIGINT}} overflow. 
> {{BIGINT}} translates to Java's {{LONG}} whose bounds are used to determine 
> whether overflow has occurred.
> BigQuery also supports {{Decimal}} and {{BigDecimal}} types, which maps to 
> Calcite's {{DECIMAL}} type. Their overflow is determined using their 
> precision and scale, and if they exceed BigQuery's limits, then overflow has 
> occurred.
> BigQuery's {{FLOAT64}} maps to Java's {{DOUBLE}} and it's {{MAX_VALUE}} and 
> {{MIN_VALUE}} are used to determine whether overflow has occurred. 



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

Reply via email to