allisonwang-db opened a new pull request #29031:
URL: https://github.com/apache/spark/pull/29031


   ### What changes were proposed in this pull request?
   This PR added a physical rule to remove redundant project nodes. A 
`ProjectExec` is redundant when
   1. It has the same output attributes and order as its child's output when 
ordering of these attributes is required.
   2. It has the same output attributes as its child's output when attribute 
output ordering is not required.
   
   For example:
   After Filter: 
   ```
   == Physical Plan ==
   *(1) Project [a#14L, b#15L, c#16, key#17] 
   +- *(1) Filter (isnotnull(a#14L) AND (a#14L > 5))
      +- *(1) ColumnarToRow
         +- FileScan parquet [a#14L,b#15L,c#16,key#17] 
   ```
   The `Project a#14L, b#15L, c#16, key#17` is redundant because its output is 
exactly the same as filter's output.
   
   Before Aggregate:
   ```
   == Physical Plan ==
   *(2) HashAggregate(keys=[key#17], functions=[sum(a#14L), last(b#15L, 
false)], output=[sum_a#39L, key#17, last_b#41L])
   +- Exchange hashpartitioning(key#17, 5), true, [id=#77]
      +- *(1) HashAggregate(keys=[key#17], functions=[partial_sum(a#14L), 
partial_last(b#15L, false)], output=[key#17, sum#49L, last#50L, valueSet#51])
         +- *(1) Project [key#17, a#14L, b#15L]
            +- *(1) Filter (isnotnull(a#14L) AND (a#14L > 100))
               +- *(1) ColumnarToRow
                  +- FileScan parquet [a#14L,b#15L,key#17] 
   ```
   The `Project key#17, a#14L, b#15L` is redundant because hash aggregate 
doesn't require child plan's output to be in a specific order.
   
   ### Why are the changes needed?
   <!--
   Please clarify why the changes are needed. For instance,
     1. If you propose a new API, clarify the use case for a new API.
     2. If you fix a bug, you can clarify why it is a bug.
   -->
   It removes unnecessary query nodes and makes query plan cleaner.
   
   ### Does this PR introduce _any_ user-facing change?
   <!--
   Note that it means *any* user-facing change including all aspects such as 
the documentation fix.
   If yes, please clarify the previous behavior and the change this PR proposes 
- provide the console output, description and/or an example to show the 
behavior difference if possible.
   If possible, please also clarify if this is a user-facing change compared to 
the released Spark versions or within the unreleased branches such as master.
   If no, write 'No'.
   -->
   No
   
   ### How was this patch tested?
   <!--
   If tests were added, say they were added here. Please make sure to add some 
test cases that check the changes thoroughly including negative and positive 
cases if possible.
   If it was tested in a way different from regular unit tests, please clarify 
how you tested step by step, ideally copy and paste-able, so that other 
reviewers can test and check, and descendants can verify in the future.
   If tests were not added, please describe why they were not added and/or why 
it was difficult to add.
   -->
   Unit tests


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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org



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

Reply via email to