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/05/02 03:32: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=17718413#comment-17718413 ]
Julian Hyde commented on CALCITE-5662:
--------------------------------------
[~oliverlee], Rather than adding {{conformance}} to {{{}SqlTypeFactory{}}}, how about refactoring {{{}SqlTypeUtil.canCastFrom(RelDataType, RelDataType, boolean){}}}, adding an overload where the 3rd parameter is of type {{{}SqlTypeMappingRule{}}}? Then changeĀ {{SqlTypeFactory.leastRestrictive}} to add an optional 3rd parameter of type {{{}SqlTypeMappingRule{}}}.
I think that new {{SqlTypeMappingRule}} instance could capture the extended (fromType, toType) pairs.
The comment in {{SqlTypeUtil}} is on the money (20 years later!):
{quote} * <p>REVIEW jvs 17-Dec-2004: the coerce param below shouldn't really be
* necessary. We're using it as a hack because
* {@link SqlTypeFactoryImpl#leastRestrictive} isn't complete enough
* yet. Once it is, this param (and the non-coerce rules of
* {@link SqlTypeAssignmentRule}) should go away.{quote}
> 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
> Labels: pull-request-available
> Time Spent: 10m
> Remaining Estimate: 0h
>
> Currently attempting to run {{SELECT CAST(BOOLEAN as INTEGER)}} will throw a {{NumberFormatException}}.
> The BigQuery dialect allows casting {{boolean}} literals 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)