rubenada commented on a change in pull request #2413:
URL: https://github.com/apache/calcite/pull/2413#discussion_r631681726



##########
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:
       Ok, seems good.
   nitpick:
   I guess with the new code, the `Objects.requireNonNull` in the three 
`Util.transform` is not necessary, since the null case has been checked (and 
early-exited) before.
   The `isNullable |= type.isNullable();` computation could be integrated into 
the new "null key+value/component loop", to just have one "pre-computation 
loop" instead of two.
   If `keyType` is `null` we could just return `null` without computing 
`valueType`
   You could add `final` to `keyType`, `valueType` and `type` variables
   




-- 
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]


Reply via email to