macroguo-ghy commented on code in PR #3721:
URL: https://github.com/apache/calcite/pull/3721#discussion_r1517571878


##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1149,6 +1149,56 @@ private static RelDataType 
mapReturnType(SqlOperatorBinding opBinding) {
         false);
   }
 
+  @SuppressWarnings("argument.type.incompatible")
+  private static RelDataType mapKeyReturnType(SqlOperatorBinding opBinding) {
+    List<RelDataType> operandType = new ArrayList<>();
+
+    operandType.add(opBinding.collectOperandTypes().get(0).getKeyType());
+    operandType.add(opBinding.collectOperandTypes().get(0).getValueType());
+    Pair<@Nullable RelDataType, @Nullable RelDataType> type =
+        getComponentTypes(
+            opBinding.getTypeFactory(), operandType);
+
+    requireNonNull(type, "inferred map type");

Review Comment:
   type is never null



##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1149,6 +1149,56 @@ private static RelDataType 
mapReturnType(SqlOperatorBinding opBinding) {
         false);
   }
 
+  @SuppressWarnings("argument.type.incompatible")
+  private static RelDataType mapKeyReturnType(SqlOperatorBinding opBinding) {
+    List<RelDataType> operandType = new ArrayList<>();
+
+    operandType.add(opBinding.collectOperandTypes().get(0).getKeyType());
+    operandType.add(opBinding.collectOperandTypes().get(0).getValueType());
+    Pair<@Nullable RelDataType, @Nullable RelDataType> type =
+        getComponentTypes(
+            opBinding.getTypeFactory(), operandType);
+
+    requireNonNull(type, "inferred map type");
+    requireNonNull(type.getKey(), "inferred map key type");
+    requireNonNull(type.getValue(), "inferred value type");
+
+    if (!type.getValue().getSqlTypeName().getName().equals("UNKNOWN")

Review Comment:
   Compare the `SqlTypeName` enum, not string



##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1458,14 +1508,14 @@ private static RelDataType 
deriveTypeMapConcat(SqlOperatorBinding opBinding) {
   @LibraryOperator(libraries = {SPARK})
   public static final SqlFunction MAP_KEYS =
       SqlBasicFunction.create(SqlKind.MAP_KEYS,
-          ReturnTypes.TO_MAP_KEYS_NULLABLE,

Review Comment:
   remove `ReturnTypes.TO_MAP_KEYS_NULLABLE` if we don't use it any more.



##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1458,14 +1508,14 @@ private static RelDataType 
deriveTypeMapConcat(SqlOperatorBinding opBinding) {
   @LibraryOperator(libraries = {SPARK})
   public static final SqlFunction MAP_KEYS =
       SqlBasicFunction.create(SqlKind.MAP_KEYS,
-          ReturnTypes.TO_MAP_KEYS_NULLABLE,
+          SqlLibraryOperators::mapKeyReturnType,
           OperandTypes.MAP);
 
   /** The "MAP_VALUES(map)" function. */
   @LibraryOperator(libraries = {SPARK})
   public static final SqlFunction MAP_VALUES =
       SqlBasicFunction.create(SqlKind.MAP_VALUES,
-          ReturnTypes.TO_MAP_VALUES_NULLABLE,

Review Comment:
   remove it if we don't use it any more.



##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1149,6 +1149,56 @@ private static RelDataType 
mapReturnType(SqlOperatorBinding opBinding) {
         false);
   }
 
+  @SuppressWarnings("argument.type.incompatible")
+  private static RelDataType mapKeyReturnType(SqlOperatorBinding opBinding) {
+    List<RelDataType> operandType = new ArrayList<>();
+
+    operandType.add(opBinding.collectOperandTypes().get(0).getKeyType());
+    operandType.add(opBinding.collectOperandTypes().get(0).getValueType());
+    Pair<@Nullable RelDataType, @Nullable RelDataType> type =
+        getComponentTypes(
+            opBinding.getTypeFactory(), operandType);
+
+    requireNonNull(type, "inferred map type");
+    requireNonNull(type.getKey(), "inferred map key type");
+    requireNonNull(type.getValue(), "inferred value type");
+
+    if (!type.getValue().getSqlTypeName().getName().equals("UNKNOWN")
+        && !type.getKey().getSqlTypeName().getName().equals("UNKNOWN")) {
+      SqlValidatorUtil.adjustTypeForMapFunctionConstructor(type, opBinding);
+    }
+
+    return SqlTypeUtil.createArrayType(
+        opBinding.getTypeFactory(),
+        requireNonNull(type.left, "inferred key type"),
+        false);
+  }
+
+  @SuppressWarnings("argument.type.incompatible")
+  private static RelDataType mapValueReturnType(SqlOperatorBinding opBinding) {
+    List<RelDataType> operandType = new ArrayList<>();
+
+    operandType.add(opBinding.collectOperandTypes().get(0).getKeyType());
+    operandType.add(opBinding.collectOperandTypes().get(0).getValueType());
+    Pair<@Nullable RelDataType, @Nullable RelDataType> type =
+        getComponentTypes(
+            opBinding.getTypeFactory(), operandType);
+
+    requireNonNull(type, "inferred map type");

Review Comment:
   type is never null



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

To unsubscribe, e-mail: commits-unsubscr...@calcite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to