sigmod commented on a change in pull request #35864:
URL: https://github.com/apache/spark/pull/35864#discussion_r838835663
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/NestedColumnAliasing.scala
##########
@@ -312,6 +312,32 @@ object NestedColumnAliasing {
}
}
+object GeneratorUnrequiredChildrenPruning {
+ def unapply(plan: LogicalPlan): Option[LogicalPlan] = plan match {
+ case p@Project(_, g: Generate) =>
+ val requiredAttrs = p.references ++ g.generator.references
+ var pruned = false
+ val newChild = if (!g.child.outputSet.subsetOf(requiredAttrs)) {
+ pruned = true
+ Project(g.child.output.filter(requiredAttrs.contains), g.child)
+ } else {
+ g.child
+ }
+ val unrequired = g.generator.references -- p.references
+ val unrequiredIndices = newChild.output.zipWithIndex.filter(t =>
unrequired.contains(t._1))
+ .map(_._2)
+ if (unrequiredIndices.toSet != g.unrequiredChildIndex.toSet) {
+ pruned = true
+ }
+ if (pruned) {
+ Some(p.copy(child = g.copy(child = newChild, unrequiredChildIndex =
unrequiredIndices)))
+ } else {
+ None
+ }
Review comment:
There seems some logic change in the new code:
https://www.diffchecker.com/wEi4OAYD, e.g., how `requiredAttrs` is obtained.
Is it possible to keep the change "mechanical", e.g.,
```
case p @ Project(_, g: Generate) if p.references != g.outputSet =>
val requiredAttrs = p.references -- g.producedAttributes ++
g.generator.references
val newChild = prunedChild(g.child, requiredAttrs)
val unrequired = g.generator.references -- p.references
val unrequiredIndices = newChild.output.zipWithIndex.filter(t =>
unrequired.contains(t._1))
.map(_._2)
if (!newChild.fastEq(g.Child) || unrequiredIndices.toSet !=
g.unrequiredChildIndex.toSet) {
p.copy(child = g.copy(child = newChild, unrequiredChildIndex =
unrequiredIndices))
} else {
None
}
```
The only difference is the last line so that we still can enter the
`GeneratorNestedColumnAliasing` branch if no rewrite happens?
--
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]