You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@calcite.apache.org by "Sergey Nuyanzin (Jira)" <ji...@apache.org> on 2024/05/06 22:20:05 UTC
[jira] [Closed] (CALCITE-6228) ELEMENT function infers incorrect return type
[ https://issues.apache.org/jira/browse/CALCITE-6228?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Sergey Nuyanzin closed CALCITE-6228.
------------------------------------
Resolved in release 1.37.0 (2024-05-06)
> ELEMENT function infers incorrect return type
> ---------------------------------------------
>
> Key: CALCITE-6228
> URL: https://issues.apache.org/jira/browse/CALCITE-6228
> Project: Calcite
> Issue Type: Bug
> Components: core
> Affects Versions: 1.36.0
> Reporter: Mihai Budiu
> Priority: Minor
> Labels: pull-request-available
> Fix For: 1.37.0
>
>
> The ELEMENT function is defined in the documentation as follows: [https://calcite.apache.org/docs/reference.html#collection-functions]
> {quote}Returns the sole element of an array or multiset; null if the collection is empty; throws if it has more than one element.
> {quote}
> However, the type inference returns just the type of the element of the collection, without changing its nullability.
> The type inference is implemented as follows in SqlStdOperatorTable:
> {code:java}
> public static final SqlFunction ELEMENT =
> SqlBasicFunction.create("ELEMENT",
> ReturnTypes.MULTISET_ELEMENT_NULLABLE,
> OperandTypes.COLLECTION);
> {code}
> However, reading the definition of MULTISET_ELEMENT_NULLABLE in ReturnTypes.java:
> {code:java}
> public static final SqlReturnTypeInference MULTISET_ELEMENT_NULLABLE =
> MULTISET.andThen(SqlTypeTransforms.TO_COLLECTION_ELEMENT_TYPE);
> {code}
> we notice that it is not forced to be nullable. Probably the correct implementation would be
> {code:java}
> public static final SqlReturnTypeInference MULTISET_ELEMENT_NULLABLE =
> MULTISET.andThen(SqlTypeTransforms.TO_COLLECTION_ELEMENT_TYPE)
> .andThen(SqlTypeTransforms.FORCE_NULLABLE);
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)