liuyongvs commented on code in PR #3262:
URL: https://github.com/apache/calcite/pull/3262#discussion_r1227567195


##########
core/src/main/java/org/apache/calcite/sql/fun/SqlLibraryOperators.java:
##########
@@ -1005,6 +1012,23 @@ private static RelDataType 
arrayReturnType(SqlOperatorBinding opBinding) {
           ReturnTypes.TO_MAP_VALUES_NULLABLE,
           OperandTypes.MAP);
 
+  private static RelDataType deriveTypeMapFromEntries(SqlOperatorBinding 
opBinding) {
+    final RelDataType entriesType = opBinding.collectOperandTypes().get(0);
+    final RelDataType entryType = entriesType.getComponentType();
+    return SqlTypeUtil.createMapType(
+        opBinding.getTypeFactory(),
+        requireNonNull(entryType.getFieldList().get(0).getType(), "inferred 
key type"),
+        requireNonNull(entryType.getFieldList().get(1).getType(), "inferred 
value type"),
+        entriesType.isNullable() || entryType.isNullable());
+  }
+

Review Comment:
   comments:
   ```
   the spark MAP_FROM_ENTRIES nullable have 2 case:
   
   1) input is nullable
   
   2) array, which contains null entry like this ,it will also return null
   
   // spark
   spark-sql> select map_from_entries(array(struct(1, 'a'), null));
   NULL 
   
   // calcite should test this
   f.checkNull("map_from_entries(array[row(1, 'a'), null])");
   f.checkType("map_from_entries(array[row(1, 'a'), null])",
       "(INTEGER, CHAR(1)) MAP");
    
   
   case class MapFromEntries(child: Expression)
     extends UnaryExpression
     with NullIntolerant
     with QueryErrorsBase {
   
     @transient
     private lazy val dataTypeDetails: Option[(MapType, Boolean, Boolean)] = 
child.dataType match {
       case ArrayType(
         StructType(Array(
           StructField(_, keyType, keyNullable, _),
           StructField(_, valueType, valueNullable, _))),
         containsNull) => Some((MapType(keyType, valueType, valueNullable), 
keyNullable, containsNull))
       case _ => None
     }
   
     @transient private lazy val nullEntries: Boolean = dataTypeDetails.get._3
   
     override def nullable: Boolean = child.nullable || nullEntries
   ```



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to