wangyum opened a new pull request #31907:
URL: https://github.com/apache/spark/pull/31907
### What changes were proposed in this pull request?
This pr move `TransposeWindow` ahead of `Operator push down` to make
`PushDownPredicates` push down more cases. For example:
```scala
spark.range(10).selectExpr("id AS a", "id AS b", "id AS c", "id AS
d").createTempView("t1")
val df = spark.sql(
"""
|SELECT *
| FROM (
| SELECT b,
| sum(d) OVER (PARTITION BY a, b),
| rank() OVER (PARTITION BY a ORDER BY c)
| FROM t1
| ) v1
|WHERE b = 2
|""".stripMargin).explain(true)
```
Before this pr:
```
== Optimized Logical Plan ==
Project [b#221L, sum(d) OVER (PARTITION BY a, b ROWS BETWEEN UNBOUNDED
PRECEDING AND UNBOUNDED FOLLOWING)#231L, RANK() OVER (PARTITION BY a ORDER BY c
ASC NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)#232]
+- Filter (b#221L = 2)
+- Window [rank(c#222L) windowspecdefinition(a#220L, c#222L ASC NULLS
FIRST, specifiedwindowframe(RowFrame, unboundedpreceding$(), currentrow$())) AS
RANK() OVER (PARTITION BY a ORDER BY c ASC NULLS FIRST ROWS BETWEEN UNBOUNDED
PRECEDING AND CURRENT ROW)#232], [a#220L], [c#222L ASC NULLS FIRST]
+- Project [b#221L, a#220L, c#222L, sum(d) OVER (PARTITION BY a, b
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)#231L]
+- Window [sum(d#223L) windowspecdefinition(a#220L, b#221L,
specifiedwindowframe(RowFrame, unboundedpreceding$(), unboundedfollowing$()))
AS sum(d) OVER (PARTITION BY a, b ROWS BETWEEN UNBOUNDED PRECEDING AND
UNBOUNDED FOLLOWING)#231L], [a#220L, b#221L]
+- Project [id#218L AS b#221L, id#218L AS d#223L, id#218L AS
a#220L, id#218L AS c#222L]
+- Range (0, 10, step=1, splits=Some(2))
```
After this pr:
```
== Optimized Logical Plan ==
Project [b#221L, sum(d) OVER (PARTITION BY a, b ROWS BETWEEN UNBOUNDED
PRECEDING AND UNBOUNDED FOLLOWING)#231L, RANK() OVER (PARTITION BY a ORDER BY c
ASC NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)#232]
+- Window [sum(d#223L) windowspecdefinition(a#220L, b#221L,
specifiedwindowframe(RowFrame, unboundedpreceding$(), unboundedfollowing$()))
AS sum(d) OVER (PARTITION BY a, b ROWS BETWEEN UNBOUNDED PRECEDING AND
UNBOUNDED FOLLOWING)#231L], [a#220L, b#221L]
+- Project [b#221L, d#223L, a#220L, RANK() OVER (PARTITION BY a ORDER BY
c ASC NULLS FIRST ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)#232]
+- Filter (b#221L = 2)
+- Window [rank(c#222L) windowspecdefinition(a#220L, c#222L ASC
NULLS FIRST, specifiedwindowframe(RowFrame, unboundedpreceding$(),
currentrow$())) AS RANK() OVER (PARTITION BY a ORDER BY c ASC NULLS FIRST ROWS
BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)#232], [a#220L], [c#222L ASC NULLS
FIRST]
+- Project [id#218L AS b#221L, id#218L AS d#223L, id#218L AS
a#220L, id#218L AS c#222L]
+- Range (0, 10, step=1, splits=Some(2))
```
### Why are the changes needed?
Improve query performance.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
Unit test.
--
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:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]