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

Julian Hyde commented on CALCITE-5557:
--------------------------------------

In your examples please use Calcite types (BOOLEAN not BOOL) and single-quoted 
character literals.

Type derivation is different from CAST. The result is nullable.

Simplification is tricky. You need to make sure that CAST simplifications are 
not accidentally applied to SAFE_CAST, but you don't want to prevent them 
altogether. How to prevent accidents? Consider making SAFE_CAST a different 
operator from CAST, perhaps with the same SqlKind, perhaps with the same 
operator class. I don't know.

You should read CALCITE-3215 and understand its idea of "safe" operators. And 
also write some new simplification tests, to make sure everything works as 
intended.

The implementor of CAST and SAFE_CAST can probably be shared.

Do the same process for SAFE_DIVIDE, even if you don't intend to implement it 
now. The right design patterns are probably the ones that work for both 
SAFE_CAST and SAFE_DIVIDE.

> Add SAFE_CAST (big 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 INT64) -> 1
> SAFE_CAST("a" as INT64) -> NULL
> SAFE_CAST("2022-12-12" as DATE) -> DATE('2022-12-12')
> SAFE_CAST(1 AS BOOL) -> true
> SAFE_CAST("A" AS BOOL) -> null
> {quote}
>  



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

Reply via email to