From 9c35ddd0c9bf69b9736130c5240e25be026905e2 Mon Sep 17 00:00:00 2001 From: gengjiaan Date: Tue, 27 Oct 2020 17:31:02 +0800 Subject: [PATCH] Optimize code --- .../window/WindowFunctionFrame.scala | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowFunctionFrame.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowFunctionFrame.scala index 2aea3a9de2c5f..7c4356cdb260c 100644 --- a/sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowFunctionFrame.scala +++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowFunctionFrame.scala @@ -129,18 +129,6 @@ abstract class OffsetWindowFunctionFrameBase( newMutableProjection(boundExpressions, Nil).target(target) } - override def prepare(rows: ExternalAppendOnlyUnsafeRowArray): Unit = { - input = rows - inputIterator = input.generateIterator() - // drain the first few rows if offset is larger than zero - inputIndex = 0 - while (inputIndex < offset) { - if (inputIterator.hasNext) inputIterator.next() - inputIndex += 1 - } - inputIndex = offset - } - override def currentLowerBound(): Int = throw new UnsupportedOperationException() override def currentUpperBound(): Int = throw new UnsupportedOperationException() @@ -163,6 +151,18 @@ class FrameLessOffsetWindowFunctionFrame( extends OffsetWindowFunctionFrameBase( target, ordinal, expressions, inputSchema, newMutableProjection, offset) { + override def prepare(rows: ExternalAppendOnlyUnsafeRowArray): Unit = { + input = rows + inputIterator = input.generateIterator() + // drain the first few rows if offset is larger than zero + inputIndex = 0 + while (inputIndex < offset) { + if (inputIterator.hasNext) inputIterator.next() + inputIndex += 1 + } + inputIndex = offset + } + override def write(index: Int, current: InternalRow): Unit = { if (inputIndex >= 0 && inputIndex < input.length) { val r = WindowFunctionFrame.getNextOrNull(inputIterator)