Github user gatorsmile commented on a diff in the pull request:
https://github.com/apache/spark/pull/11565#discussion_r55636068
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
---
@@ -387,6 +381,14 @@ object ColumnPruning extends Rule[LogicalPlan] {
// Can't prune the columns on LeafNode
case p @ Project(_, l: LeafNode) => p
+ // Prune windowExpressions and child of Window
+ case p @ Project(_, w: Window) if (w.outputSet --
p.references).nonEmpty =>
+ val newWindowExprs =
w.windowExpressions.filter(p.references.contains)
+ val newGrandChild = prunedChild(w.child, w.references ++
p.references)
--- End diff --
I see your points. Yeah, you are right. We should use the `newWindowExprs`.
For the second part, we still need `p.references`. After this PR, the
`output` of `Window` is ```child.output ++
windowExpression.map(_.toAttribute)```. Thus, the attributes used in `Project`
have to be kept. Is my understanding right?
How about this?
```
prunedChild(w.child, AttributeSet(newWindowExprs.flatMap(_.references)) ++
p.references)
```
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]