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

Oliver Lee commented on CALCITE-5557:
-------------------------------------

I have been investigating the test failures: 
[https://github.com/apache/calcite/actions/runs/4370214681/jobs/7644894373]

Specifically this case  
[https://github.com/apache/calcite/blob/main/testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java#L5526]
 , it seems that on main branch, {{trunc(cast(42.345 as decimal(2,3)),2)}} 
actually throws an exception because it fails this check: 
https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql/type/SqlTypeUtil.java#L1809,
 however the exceptions were previously just swallowed 

> Add SAFE_CAST (BigQuery compatibility)
> --------------------------------------
>
>                 Key: CALCITE-5557
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5557
>             Project: Calcite
>          Issue Type: New Feature
>            Reporter: Oliver Lee
>            Assignee: Oliver Lee
>            Priority: Minor
>
> Implement SAFE_CAST per BigQuery specifications
> [https://cloud.google.com/bigquery/docs/reference/standard-sql/functions-and-operators#safe_casting]
> Equivalent to CAST(), except it will return {{null}} instead of throwing an 
> exception if the casting fails.
> {quote}SAFE_CAST('1' as INT) -> 1
> SAFE_CAST('a' as INT) -> NULL
> SAFE_CAST("2022-12-12" as DATE) -> DATE('2022-12-12')
> SAFE_CAST(1 AS BOOLEAN) -> true
> SAFE_CAST('A' AS BOOLEAN) -> null
> {quote}
>  



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

Reply via email to