[
https://issues.apache.org/jira/browse/CALCITE-5557?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17697581#comment-17697581
]
Julian Hyde commented on CALCITE-5557:
--------------------------------------
I don't know. It's a judgment call as to what causes the least amount of chaos
in the RexToLixTranslator. It's possible that you need a toIntSafe method (and
corresponding methods for every data type), but that seems like a lot to
maintain (because there are a lot of data types). It's possible that {{toInt}}
could somehow declare the exceptions that it might throw and RexToLixTranslator
could generate a "catch (Ex1 | Ex2) \{ return null; }" clause.
Take the time to understand how {{implementSafe}} works, and how we can use
methods with primitive arguments to implement SQL calls with nullable
arguments. (Note that "safe" in that context means something different.) Maybe
there is a similar trick that can be used here.
> 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)