mingmwang commented on PR #4484:
URL: 
https://github.com/apache/arrow-datafusion/pull/4484#issuecomment-1338696095

   I still think the `SubqueryAlias` should be removed at the early stage of 
the logical optimizer.
   I just run the same SQL on SparkSQL and find the SubqueryAlias was totally 
removed.
   
   Spark SQL Output: 
   
   ````
   +----------------------------------------------------+
   |                        plan                        |
   +----------------------------------------------------+
   | == Parsed Logical Plan ==
   CTE [_sample_data, _data2]
   :  :- SubqueryAlias _sample_data
   :  :  +- Union
   :  :     :- Union
   :  :     :  :- Union
   :  :     :  :  :- Project [1 AS a#5683777, aa AS b#5683778]
   :  :     :  :  :  +- OneRowRelation
   :  :     :  :  +- Project [3 AS a#5683779, aa AS b#5683780]
   :  :     :  :     +- OneRowRelation
   :  :     :  +- Project [5 AS a#5683781, bb AS b#5683782]
   :  :     :     +- OneRowRelation
   :  :     +- Project [7 AS a#5683783, bb AS b#5683784]
   :  :        +- OneRowRelation
   :  +- 'SubqueryAlias _data2
   :     +- 'Project ['row_number() windowspecdefinition('s.b, 's.a ASC NULLS 
FIRST, unspecifiedframe$()) AS seq#5683785, 's.a, 's.b]
   :        +- 'SubqueryAlias s
   :           +- 'UnresolvedRelation [_sample_data]
   +- 'Sort ['d.b ASC NULLS FIRST], true
      +- 'Aggregate ['d.b], ['d.b, 'MAX('d.a) AS max_a#5683776]
         +- 'SubqueryAlias d
            +- 'UnresolvedRelation [_data2]
   
   == Analyzed Logical Plan ==
   b: string, max_a: int
   Project [b#5683778, max_a#5683776]
   +- Sort [b#5683778 ASC NULLS FIRST], true
      +- Aggregate [b#5683778], [b#5683778, max(a#5683777) AS max_a#5683776]
         +- SubqueryAlias d
            +- SubqueryAlias _data2
               +- Project [seq#5683785, a#5683777, b#5683778]
                  +- Project [a#5683777, b#5683778, seq#5683785, seq#5683785]
                     +- Window [row_number() windowspecdefinition(b#5683778, 
a#5683777 ASC NULLS FIRST, specifiedwindowframe(RowFrame, 
unboundedpreceding$(), currentrow$())) AS seq#5683785], [b#5683778], [a#5683777 
ASC NULLS FIRST]
                        +- Project [a#5683777, b#5683778]
                           +- SubqueryAlias s
                              +- SubqueryAlias _sample_data
                                 +- Union
                                    :- Union
                                    :  :- Union
                                    :  :  :- Project [1 AS a#5683777, aa AS 
b#5683778]
                                    :  :  :  +- OneRowRelation
                                    :  :  +- Project [3 AS a#5683779, aa AS 
b#5683780]
                                    :  :     +- OneRowRelation
                                    :  +- Project [5 AS a#5683781, bb AS 
b#5683782]
                                    :     +- OneRowRelation
                                    +- Project [7 AS a#5683783, bb AS b#5683784]
                                       +- OneRowRelation
   
   == Optimized Logical Plan ==
   Sort [b#5683778 ASC NULLS FIRST], true
   +- Aggregate [b#5683778], [b#5683778, max(a#5683777) AS max_a#5683776]
      +- Union
         :- Project [1 AS a#5683777, aa AS b#5683778]
         :  +- OneRowRelation
         :- Project [3 AS a#5683779, aa AS b#5683780]
         :  +- OneRowRelation
         :- Project [5 AS a#5683781, bb AS b#5683782]
         :  +- OneRowRelation
         +- Project [7 AS a#5683783, bb AS b#5683784]
            +- OneRowRelation
   
   
   ````
   


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

Reply via email to