Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
1.36.0
Description
The ELEMENT function is defined in the documentation as follows: https://calcite.apache.org/docs/reference.html#collection-functions
Returns the sole element of an array or multiset; null if the collection is empty; throws if it has more than one element.
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:
public static final SqlFunction ELEMENT = SqlBasicFunction.create("ELEMENT", ReturnTypes.MULTISET_ELEMENT_NULLABLE, OperandTypes.COLLECTION);
However, reading the definition of MULTISET_ELEMENT_NULLABLE in ReturnTypes.java:
public static final SqlReturnTypeInference MULTISET_ELEMENT_NULLABLE = MULTISET.andThen(SqlTypeTransforms.TO_COLLECTION_ELEMENT_TYPE);
we notice that it is not forced to be nullable. Probably the correct implementation would be
public static final SqlReturnTypeInference MULTISET_ELEMENT_NULLABLE = MULTISET.andThen(SqlTypeTransforms.TO_COLLECTION_ELEMENT_TYPE) .andThen(SqlTypeTransforms.FORCE_NULLABLE);
Attachments
Issue Links
- links to