Github user hvanhovell commented on a diff in the pull request:

    https://github.com/apache/spark/pull/16255#discussion_r92293834
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
 ---
    @@ -416,8 +418,8 @@ object ColumnPruning extends Rule[LogicalPlan] {
         case w: Window if w.windowExpressions.isEmpty => w.child
     
         // Eliminate no-op Projects
    -    case p @ Project(_, child) if sameOutput(child.output, p.output) => 
child
    -
    +    case p @ Project(_, child) if sameOutput(child.output, p.output) =>
    +      if (child.isInstanceOf[CatalogRelation]) p else child
    --- End diff --
    
    This works in your example case, but will fail for a more complex query.
    
    The problem is that the transform on L199 also modifies parts of the tree, 
that are totally unrelated to the projection at hand. In this case right side 
of the join. This can currently only happen in case of a self-join on a CTE, 
such a tree can contain duplicate attribute ids because we expand the tree 
after we have analyzed the CTE.


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to