wangyum commented on code in PR #48789:
URL: https://github.com/apache/spark/pull/48789#discussion_r1848573244


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/RemoveRedundantProjects.scala:
##########
@@ -58,7 +58,8 @@ object RemoveRedundantProjects extends Rule[SparkPlan] {
           p.mapChildren(removeProject(_, false))
         }
       case op: TakeOrderedAndProjectExec =>
-        op.mapChildren(removeProject(_, false))
+        // TakeOrderedAndProjectExec requires keep column ordering if AQE is 
enabled.

Review Comment:
   When AQE is disabled, using `op.projectList == op.child.output` will affect 
the plan.
   Before:
   ```
   TakeOrderedAndProject(limit=100, orderBy=[year#271 ASC NULLS 
FIRST,course#270 ASC NULLS FIRST], 
output=[year#271,course#270,earnings#272,balance#269])
   +- Window [sum(earnings#272) windowspecdefinition(year#271 ASC NULLS FIRST, 
course#270 ASC NULLS FIRST, specifiedwindowframe(RangeFrame, 
unboundedpreceding$(), currentrow$())) AS balance#269], [year#271 ASC NULLS 
FIRST, course#270 ASC NULLS FIRST]
      +- *(2) Sort [year#271 ASC NULLS FIRST, course#270 ASC NULLS FIRST], 
false, 0
         +- Exchange SinglePartition, ENSURE_REQUIREMENTS, [plan_id=122]
            +- *(1) ColumnarToRow
               +- FileScan parquet 
spark_catalog.default.t[course#270,year#271,earnings#272]
   ```
   After:
   ```
   TakeOrderedAndProject(limit=100, orderBy=[year#271 ASC NULLS 
FIRST,course#270 ASC NULLS FIRST], 
output=[year#271,course#270,earnings#272,balance#269])
   +- Window [sum(earnings#272) windowspecdefinition(year#271 ASC NULLS FIRST, 
course#270 ASC NULLS FIRST, specifiedwindowframe(RangeFrame, 
unboundedpreceding$(), currentrow$())) AS balance#269], [year#271 ASC NULLS 
FIRST, course#270 ASC NULLS FIRST]
      +- *(2) Sort [year#271 ASC NULLS FIRST, course#270 ASC NULLS FIRST], 
false, 0
         +- Exchange SinglePartition, ENSURE_REQUIREMENTS, [plan_id=122]
            +- *(1) Project [year#271, course#270, earnings#272]
               +- *(1) ColumnarToRow
                  +- FileScan parquet 
spark_catalog.default.t[course#270,year#271,earnings#272]
   ```



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

Reply via email to