[
https://issues.apache.org/jira/browse/CALCITE-5557?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17697214#comment-17697214
]
Oliver Lee commented on CALCITE-5557:
-------------------------------------
I'm still in the process of going through the linked Jira cases and commits but
I have a question:
Assuming that the type derivation makes the result nullable, the type
simplification is handled correctly, won't we still end up with it resolving
and executing {{toInt()}} in {{SAFE_CAST('a' as INT)}} , and throw and error?
Does there need to be:
* a mechanism to detect early, short circuit and return null instead of
throwing
* or a mechanism to catch the exception and then return null
Or is all of this supposed to be done in the simplification and that it
shouldn't be executing scenarios that would throw?
> 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)