wangyum commented on a change in pull request #31677:
URL: https://github.com/apache/spark/pull/31677#discussion_r602877074
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -913,14 +913,27 @@ object OptimizeWindowFunctions extends Rule[LogicalPlan] {
* independent and are of the same window function type, collapse into the
parent.
*/
object CollapseWindow extends Rule[LogicalPlan] {
+ private def windowsCompatible(w1: Window, w2: Window): Boolean = {
+ w1.partitionSpec == w2.partitionSpec &&
+ w1.orderSpec == w2.orderSpec &&
+ w1.references.intersect(w2.windowOutputSet).isEmpty &&
+ w1.windowExpressions.nonEmpty && w2.windowExpressions.nonEmpty &&
+ // This assumes Window contains the same type of window expressions.
This is ensured
+ // by ExtractWindowFunctions.
+ WindowFunctionType.functionType(w1.windowExpressions.head) ==
+ WindowFunctionType.functionType(w2.windowExpressions.head)
+ }
+
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) =>
Review comment:
Two more spaces?
##########
File path:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala
##########
@@ -913,14 +913,27 @@ object OptimizeWindowFunctions extends Rule[LogicalPlan] {
* independent and are of the same window function type, collapse into the
parent.
*/
object CollapseWindow extends Rule[LogicalPlan] {
+ private def windowsCompatible(w1: Window, w2: Window): Boolean = {
+ w1.partitionSpec == w2.partitionSpec &&
+ w1.orderSpec == w2.orderSpec &&
+ w1.references.intersect(w2.windowOutputSet).isEmpty &&
+ w1.windowExpressions.nonEmpty && w2.windowExpressions.nonEmpty &&
+ // This assumes Window contains the same type of window expressions.
This is ensured
+ // by ExtractWindowFunctions.
+ WindowFunctionType.functionType(w1.windowExpressions.head) ==
+ WindowFunctionType.functionType(w2.windowExpressions.head)
+ }
+
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) =>
Review comment:
Two more spaces?
--
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]