Skip to content

Commit 6923dd1

Browse files
committed
improve OptimizeWindowFunctions.
1 parent f2ceacd commit 6923dd1

File tree

1 file changed

+6
-3
lines changed
  • sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer

1 file changed

+6
-3
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/optimizer/Optimizer.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,9 +811,12 @@ object CollapseRepartition extends Rule[LogicalPlan] {
811811
*/
812812
object OptimizeWindowFunctions extends Rule[LogicalPlan] {
813813
def apply(plan: LogicalPlan): LogicalPlan = plan resolveExpressions {
814-
case we @ WindowExpression(AggregateExpression(first: First, _, _, _, _), spec)
815-
if spec.orderSpec.nonEmpty &&
816-
spec.frameSpecification.asInstanceOf[SpecifiedWindowFrame].frameType == RowFrame =>
814+
case we @ WindowExpression(AggregateExpression(first: First, _, _, _, _),
815+
WindowSpecDefinition(_, orderSpec, frameSpecification: SpecifiedWindowFrame))
816+
if orderSpec.nonEmpty && frameSpecification.frameType == RowFrame &&
817+
frameSpecification.lower == UnboundedPreceding &&
818+
(frameSpecification.upper == UnboundedFollowing ||
819+
frameSpecification.upper == CurrentRow) =>
817820
we.copy(windowFunction = NthValue(first.child, Literal(1), first.ignoreNulls))
818821
}
819822
}

0 commit comments

Comments
 (0)