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

Oliver Lee edited comment on CALCITE-5557 at 3/9/23 5:11 PM:
-------------------------------------------------------------

Julian, can you take a look at this initial PR? 
[https://github.com/apache/calcite/pull/3093] 

 

I was able to reuse most of the related CAST implementor/ functions.

 

I made typing changes such that if it is SAFE_CAST, then the return type is 
nullable, and if any exception/error is thrown then it returns the null literal 
early. 

I still need to add simplification tests

 


was (Author: JIRAUSER297744):
Julian, can you take a look at this initial PR? 
[https://github.com/apache/calcite/pull/3093] 

 

I was able to reuse most of the related CAST implementor/ functions.

 

I made typing changes such that if it is SAFE_CAST, then the return type is 
nullable, and if any exception/error is thrown then it returns the null literal 
early. 

 

 

> 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