Github user cloud-fan commented on a diff in the pull request:
https://github.com/apache/spark/pull/18576#discussion_r177671867
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
---
@@ -1309,3 +1311,20 @@ object RemoveRepetitionFromGroupExpressions extends
Rule[LogicalPlan] {
}
}
}
+
+/**
+ * Updates nullability in [[AttributeReference]]s if nullability is
different between
+ * non-leaf plan's expressions and the children output.
+ */
+object UpdateNullabilityInAttributeReferences extends Rule[LogicalPlan] {
+ def apply(plan: LogicalPlan): LogicalPlan = plan transformUp {
+ case p if !p.isInstanceOf[LeafNode] =>
+ val nullabilityMap = AttributeMap(p.children.flatMap(_.output).map {
x => x -> x.nullable })
+ p transformExpressions {
+ case ar: AttributeReference =>
+ nullabilityMap.get(ar).filterNot(_ == ar.nullable).map {
nullable =>
--- End diff --
can't we just write
```
case a: AttributeReference if nullabilityMap.contains(a) =>
a.withNullability(nullabilityMap(a))
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]