Skip to content

Commit

Permalink
Optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
beliefer committed Oct 27, 2020
1 parent fd59f6e commit 72e7805
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ trait WindowExecBase extends UnaryExecNode {
child.output,
(expressions, schema) =>
MutableProjection.create(expressions, schema),
offset - 1)
offset)
}
case ("UNBOUNDED_PRECEDING_OFFSET", _, IntegerLiteral(offset), _) =>
target: InternalRow => {
Expand All @@ -212,7 +212,7 @@ trait WindowExecBase extends UnaryExecNode {
child.output,
(expressions, schema) =>
MutableProjection.create(expressions, schema),
offset - 1)
offset)
}

// Entire Partition Frame.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ class UnboundedOffsetWindowFunctionFrame(

override def prepare(rows: ExternalAppendOnlyUnsafeRowArray): Unit = {
input = rows
if (offset >= input.length) {
if (offset > input.length) {
fillDefaultValue(EmptyRow)
} else {
inputIterator = input.generateIterator()
// drain the first few rows if offset is larger than zero
// drain the first few rows if offset is larger than one
inputIndex = 0
while (inputIndex < offset) {
while (inputIndex < offset - 1) {
if (inputIterator.hasNext) inputIterator.next()
inputIndex += 1
}
Expand Down Expand Up @@ -240,7 +240,14 @@ class UnboundedPrecedingOffsetWindowFunctionFrame(
var selectedRow: UnsafeRow = null

override def prepare(rows: ExternalAppendOnlyUnsafeRowArray): Unit = {
super.prepare(rows)
input = rows
inputIterator = input.generateIterator()
// drain the first few rows if offset is larger than one
inputIndex = 0
while (inputIndex < offset - 1) {
if (inputIterator.hasNext) inputIterator.next()
inputIndex += 1
}
if (inputIndex >= 0 && inputIndex < input.length) {
selectedRow = WindowFunctionFrame.getNextOrNull(inputIterator)
}
Expand Down

0 comments on commit 72e7805

Please sign in to comment.