wangyum commented on a change in pull request #31677:
URL: https://github.com/apache/spark/pull/31677#discussion_r602817891
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -914,13 +914,27 @@ object OptimizeWindowFunctions extends Rule[LogicalPlan] {
*/
object CollapseWindow extends Rule[LogicalPlan] {
def apply(plan: LogicalPlan): LogicalPlan = plan transformUp {
- case w1 @ Window(we1, ps1, os1, w2 @ Window(we2, ps2, os2, grandChild))
- if ps1 == ps2 && os1 == os2 &&
w1.references.intersect(w2.windowOutputSet).isEmpty &&
- we1.nonEmpty && we2.nonEmpty &&
- // This assumes Window contains the same type of window expressions.
This is ensured
- // by ExtractWindowFunctions.
- WindowFunctionType.functionType(we1.head) ==
WindowFunctionType.functionType(we2.head) =>
+ case w1 @ Window(we1, _, _, w2 @ Window(we2, _, _, grandChild))
+ if windowsCompatible(w1, w2) =>
w1.copy(windowExpressions = we2 ++ we1, child = grandChild)
+
+ case w1 @ Window(we1, _, _, Project(pl, w2 @ Window(we2, _, _,
grandChild)))
+ if windowsCompatible(w1, w2) &&
w1.references.subsetOf(grandChild.outputSet) =>
+ Project(
+ pl ++ w1.windowOutputSet,
+ w1.copy(windowExpressions = we2 ++ we1, child = grandChild)
+ )
Review comment:
```scala
Project(
pl ++ w1.windowOutputSet,
w1.copy(windowExpressions = we2 ++ we1, child = grandChild)
)
```
to
```scala
Project(
pl ++ w1.windowOutputSet,
w1.copy(windowExpressions = we2 ++ we1, child = grandChild))
```
?
--
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]