You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/09/17 02:43:04 UTC

[GitHub] [spark] cloud-fan commented on a change in pull request #34025: [SPARK-36673][SQL] Fix incorrect schema of nested types of union

cloud-fan commented on a change in pull request #34025:
URL: https://github.com/apache/spark/pull/34025#discussion_r710680268



##########
File path: sql/catalyst/src/main/scala/org/apache/spark/sql/types/StructType.scala
##########
@@ -559,6 +559,42 @@ object StructType extends AbstractDataType {
       case _ => dt
     }
 
+  /**
+   * This works a little similarly to `merge`, but it does not actually merge two DataTypes.
+   * This method just merges nullability.
+   */
+  private[sql] def mergeNullability(left: DataType, right: DataType): DataType =
+    (left, right) match {
+      case (ArrayType(leftElementType, leftContainsNull),
+          ArrayType(rightElementType, rightContainsNull)) =>
+        ArrayType(
+          mergeNullability(leftElementType, rightElementType),
+          leftContainsNull || rightContainsNull)
+
+      case (MapType(leftKeyType, leftValueType, leftContainsNull),
+          MapType(rightKeyType, rightValueType, rightContainsNull)) =>
+        MapType(
+          mergeNullability(leftKeyType, rightKeyType),
+          mergeNullability(leftValueType, rightValueType),
+          leftContainsNull || rightContainsNull)
+
+      case (StructType(leftFields), StructType(rightFields)) =>
+        require(leftFields.size == rightFields.size, "To merge nullability, " +
+          "two structs must have same number of fields.")

Review comment:
       is this error user-facing?




-- 
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: reviews-unsubscribe@spark.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org