viirya commented on a change in pull request #34025:
URL: https://github.com/apache/spark/pull/34025#discussion_r710529665
##########
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(
+ merge(leftElementType, rightElementType),
+ leftContainsNull || rightContainsNull)
+
+ case (MapType(leftKeyType, leftValueType, leftContainsNull),
+ MapType(rightKeyType, rightValueType, rightContainsNull)) =>
+ MapType(
+ merge(leftKeyType, rightKeyType),
+ merge(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.")
+
+ val newFields = leftFields.zip(rightFields).map {
Review comment:
Let me add test case for it.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]