aboutsummaryrefslogtreecommitdiff
path: root/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
diff options
context:
space:
mode:
Diffstat (limited to 'sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala')
-rw-r--r--sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala28
1 files changed, 9 insertions, 19 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
index 5210f42c55..cc62d5e7c8 100644
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
@@ -1663,27 +1663,17 @@ class Analyzer(
}
}.toSeq
- // Third, for every Window Spec, we add a Window operator and set currentChild as the
- // child of it.
- var currentChild = child
- var i = 0
- while (i < groupedWindowExpressions.size) {
- val ((partitionSpec, orderSpec), windowExpressions) = groupedWindowExpressions(i)
- // Set currentChild to the newly created Window operator.
- currentChild =
- Window(
- windowExpressions,
- partitionSpec,
- orderSpec,
- currentChild)
-
- // Move to next Window Spec.
- i += 1
- }
+ // Third, we aggregate them by adding each Window operator for each Window Spec and then
+ // setting this to the child of the next Window operator.
+ val windowOps =
+ groupedWindowExpressions.foldLeft(child) {
+ case (last, ((partitionSpec, orderSpec), windowExpressions)) =>
+ Window(windowExpressions, partitionSpec, orderSpec, last)
+ }
- // Finally, we create a Project to output currentChild's output
+ // Finally, we create a Project to output windowOps's output
// newExpressionsWithWindowFunctions.
- Project(currentChild.output ++ newExpressionsWithWindowFunctions, currentChild)
+ Project(windowOps.output ++ newExpressionsWithWindowFunctions, windowOps)
} // end of addWindow
// We have to use transformDown at here to make sure the rule of