dongjoon-hyun commented on code in PR #60729:
URL: https://github.com/apache/spark/pull/60729#discussion_r4645145327
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/UpdateAttributeNullability.scala:
##########
@@ -110,4 +111,20 @@ object UpdateAttributeNullability extends
Rule[LogicalPlan] {
}
if (newOutput == e.output) e else e.copy(output = newOutput)
}
+
+ // Generate derives the nullability of its generator output attributes from
the element schema
+ // of its generator when it is built. The element schema may become nullable
later when this
+ // rule updates the attributes the generator references, e.g., a column of a
Dataset that an
+ // outer join makes nullable, so widen the nullability of the generator
output attributes
+ // accordingly, keeping their expression IDs. Only the fields that this rule
makes nullable are
+ // considered, as some generators declare all fields nullable while their
output attributes
+ // keep a narrower nullability, e.g., `ReplicateRows` built for EXCEPT ALL.
+ private def widenOutputNullability(g: Generate, oldGenerate: Generate):
Generate = {
+ val fields = g.generator.elementSchema.fields
+ val oldFields = oldGenerate.generator.elementSchema.fields
+ val newOutput = g.generatorOutput.zipWithIndex.map { case (attr, index) =>
+ attr.withNullability(attr.nullable || (fields(index).nullable &&
!oldFields(index).nullable))
Review Comment:
Thank you, @peter-toth. I applied your suggestion and added the struct field
query to the test as a second `checkAnswer`. I also updated the migration guide
entry and the PR description for the nested case.
--
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]