You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Julian Hyde (Jira)" <ji...@apache.org> on 2023/04/19 22:31:00 UTC

[jira] [Commented] (CALCITE-5662) CAST(BOOLEAN as INTEGER) throws a NumberFormatException

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

Julian Hyde commented on CALCITE-5662:
--------------------------------------

The current behavior is correct per the SQL standard. (Actually we should give a validation error, rather than throwing NumberFormatException.)

If you allow the type conversions above it should be enabled via some flag. I'm not sure whether conformance or type system is the right place to put that flag. Maybe you can suggest something.

You will need to update the [SQL reference|https://calcite.apache.org/docs/reference.html#implicit-type-conversion].

 

> CAST(BOOLEAN as INTEGER) throws a NumberFormatException
> -------------------------------------------------------
>
>                 Key: CALCITE-5662
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5662
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Oliver Lee
>            Assignee: Oliver Lee
>            Priority: Minor
>
> Currently attempting to run {{SELECT CAST(BOOLEAN as INTEGER)}} will throw a {{NumberFormatException}}.
> The BigQuery dialect allows casting {{boolean}} to the following:  {{string}}, {{int64}} , {{tinyint}}, {{smallint}}, {{bigint}}
> src: https://cloud.google.com/bigquery/docs/reference/standard-sql/conversion_functions 
> Desired behavior:
> {{SELECT CAST(TRUE as INTEGER)}} -> {{1}}
> {{SELECT CAST(TRUE as BIGINT)}} -> {{1}}
> {{SELECT CAST(FALSE as INTEGER)}} -> {{0}}
> {{SELECT CAST(null as INTEGER)}} -> {{null}}



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