vlsi commented on a change in pull request #2413:
URL: https://github.com/apache/calcite/pull/2413#discussion_r631740972
##########
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:
The reason it complains is that `RelDataType#getKeyType()` is nullable,
while `MapSqlType#getKeyType()` is non-nullable.
The checker is not sure if `getKeyType()` is guaranteed to return the same
value every time.
If you cast `t` to `MapSqlType`, then it would work without `requireNonNull`.
An alternative approaches are:
a) Make `leastRestrictive` return `null` when `null` is among its arguments.
Currently `leastRestrictive` would fail with NPE
b) Rework `leastRestrictive` into builder-like API, so it could indicate to
the caller that no more types are needed. The user could instantiate a couple
of builders (e.g. key builder, value builder), iterate over the types, and
build the common type (e.g. right inside `for (RelDataType type: types)`)
--
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]