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

Mihai Budiu commented on CALCITE-6328:
--------------------------------------

[~tanclary] I think you have written the code to implement the SAFE_* 
functions. 
I will probably need to disable the broken tests in the fix for [CALCITE-6322].
There are some broken tests in big-query.iq, where 
{code:sql}
SELECT SAFE_ADD(9, cast(9.999999999999999999e75 as DECIMAL(38, 19)))
{code}
fails in the cast, because the type DECIMAL(38, 19) cannot actually represent 
the value at all.

> The BigQuery functions SAFE_* do not match the BigQuery specification
> ---------------------------------------------------------------------
>
>                 Key: CALCITE-6328
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6328
>             Project: Calcite
>          Issue Type: Bug
>          Components: core
>    Affects Versions: 1.36.0
>            Reporter: Mihai Budiu
>            Priority: Minor
>
> The BigQuery dialect does not support DECIMAL values with arbitrary types: it 
> only supports two fixed types: NUMERIC and BIGNUMERIC, both with fixed 
> precision and scale.
> The runtime implementation of the SAFE_* functions uses the following helper 
> in SqlFunctions:
> {code:java}
>   /** Returns whether a BigDecimal value is safe (that is, has not 
> overflowed).
>    * According to BigQuery, BigDecimal overflow occurs if the precision is 
> greater
>    * than 76 or the scale is greater than 38. */
>   private static boolean safeDecimal(BigDecimal b) {
>     return b.scale() <= 38 && b.precision() <= 76;
>   }
> {code}
> This helper does not handle correctly NUMERIC value, only BIGNUMERIC.
> Moreover, all the tests in SqlOperatorTests use a type system which doesn't 
> even support DECIMAL values wider than 38 digits. So a test like the 
> following:
> {code:java}
>     f.checkNull("safe_add(cast(-9.9e75 as DECIMAL(76, 0)), "
>         + "cast(-9.9e75 as DECIMAL(76, 0)))");
> {code}
> cannot even create the expected BigDecimal value correctly.
> This surfaced during the attempt to fix [CALCITE-6322]: once the casts to 
> DECIMAL are implemented, some of these tests break.



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

Reply via email to