Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/11565#discussion_r55776014
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -384,9 +378,21 @@ object ColumnPruning extends Rule[LogicalPlan] {
         // Eliminate no-op Projects
         case p @ Project(projectList, child) if sameOutput(child.output, 
p.output) => child
     
    +    // Eliminate no-op Window
    +    case w: Window if w.windowExpressions.isEmpty => w.child
    +
         // 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)
    --- End diff --
    
    After rethink about it, seems we can still separate it into 2 rules.
    We can add a `def windowOutputSet = 
AttributeSet(windowExpressions.map(_.toAttribute))` to `Window` operator, and 
change the first case to `case p @ Project(_, w: Window) if (w.windowOutputSet 
-- p.references).nonEmpty =>` and filter out useless window expressions


---
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]

Reply via email to