tanelk commented on a change in pull request #31980:
URL: https://github.com/apache/spark/pull/31980#discussion_r602727796
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -991,13 +991,24 @@ object TransposeWindow extends Rule[LogicalPlan] {
})
}
+ private def windowsCompatible(w1: Window, w2: Window): Boolean = {
+ w1.references.intersect(w2.windowOutputSet).isEmpty &&
+ w1.expressions.forall(_.deterministic) &&
+ w2.expressions.forall(_.deterministic) &&
+ compatiblePartitions(w1.partitionSpec, w2.partitionSpec)
+ }
+
def apply(plan: LogicalPlan): LogicalPlan = plan transformUp {
- case w1 @ Window(we1, ps1, os1, w2 @ Window(we2, ps2, os2, grandChild))
- if w1.references.intersect(w2.windowOutputSet).isEmpty &&
- w1.expressions.forall(_.deterministic) &&
- w2.expressions.forall(_.deterministic) &&
- compatiblePartitions(ps1, ps2) =>
- Project(w1.output, Window(we2, ps2, os2, Window(we1, ps1, os1,
grandChild)))
+ case w1 @ Window(_, _, _, w2 @ Window(_, _, _, grandChild))
+ if windowsCompatible(w1, w2) =>
+ Project(w1.output, w2.copy(child = w1.copy(child = grandChild)))
+
+ case w1 @ Window(_, _, _, Project(pl, w2 @ Window(_, _, _, grandChild)))
+ if windowsCompatible(w1, w2) &&
w1.references.subsetOf(grandChild.outputSet) =>
Review comment:
The test case `SPARK-34807: don't transpose two windows if project
between them generates an input column` would fail without it.
--
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]