rubenada commented on a change in pull request #2413:
URL: https://github.com/apache/calcite/pull/2413#discussion_r630817348
##########
File path:
core/src/main/java/org/apache/calcite/rel/type/RelDataTypeFactoryImpl.java
##########
@@ -257,6 +260,35 @@ private RelDataType createStructType(
return createTypeWithNullability(builder.build(), isNullable);
}
+ protected @Nullable RelDataType leastRestrictiveCollectionType(
+ final List<RelDataType> types, SqlTypeName sqlTypeName) {
+ assert sqlTypeName == SqlTypeName.ARRAY
+ || sqlTypeName == SqlTypeName.MULTISET || sqlTypeName ==
SqlTypeName.MAP;
+ boolean isNullable = false;
+ for (RelDataType type : types) {
+ isNullable |= type.isNullable();
+ }
+ if (sqlTypeName == SqlTypeName.MAP) {
+ RelDataType keyType = leastRestrictive(
+ Util.transform(types, t -> Objects.requireNonNull(t.getKeyType())));
Review comment:
I have the impression that, with this code, when trying to calculate an
"impossible" leastRestrictive (e.g. between MAP and ARRAY, or MULTISET and
VARCHAR), instead of returning `null` (as it should per
`RelDataTypeFactory#leastRestrictive` contract), it would get a NPE.
Maybe this method should add a pre-check to verify that all the types in the
list have the "expected" SqlTypeName (either MAP or MULTISET or ARRAY), before
going on (and if the pre-check fails, return `null`). WDYT?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]