beliefer commented on a change in pull request #29800:
URL: https://github.com/apache/spark/pull/29800#discussion_r512387456
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowFunctionFrame.scala
##########
@@ -151,10 +169,69 @@ final class OffsetWindowFunctionFrame(
}
inputIndex += 1
}
+}
- override def currentLowerBound(): Int = throw new
UnsupportedOperationException()
+/**
+ * The unbounded offset window frame calculates frames containing NTH_VALUE
statements.
+ * The unbounded offset window frame return the same value for all rows in the
window partition.
+ */
+class UnboundedOffsetWindowFunctionFrame(
+ target: InternalRow,
+ ordinal: Int,
+ expressions: Array[OffsetWindowSpec],
+ inputSchema: Seq[Attribute],
+ newMutableProjection: (Seq[Expression], Seq[Attribute]) =>
MutableProjection,
+ offset: Int)
+ extends OffsetWindowFunctionFrameBase(
+ target, ordinal, expressions, inputSchema, newMutableProjection, offset) {
- override def currentUpperBound(): Int = throw new
UnsupportedOperationException()
+ override def prepare(rows: ExternalAppendOnlyUnsafeRowArray): Unit = {
+ super.prepare(rows)
+ if (inputIndex >= 0 && inputIndex < input.length) {
+ val r = WindowFunctionFrame.getNextOrNull(inputIterator)
+ projection(r)
+ } else {
+ fillDefaultValue(EmptyRow)
+ }
+ }
+
+ override def write(index: Int, current: InternalRow): Unit = {
+ // The results are the same for each row in the partition, and have been
evaluated in prepare.
+ // Don't need to recalculate here.
+ }
+}
+
+/**
+ * The unbounded preceding offset window frame calculates frames containing
NTH_VALUE statements.
+ * The unbounded preceding offset window frame return the same value for rows
which index
+ * (starting from 1) equal to or greater than offset in the window partition.
+ */
+class UnboundedPrecedingOffsetWindowFunctionFrame(
+ target: InternalRow,
+ ordinal: Int,
+ expressions: Array[OffsetWindowSpec],
+ inputSchema: Seq[Attribute],
+ newMutableProjection: (Seq[Expression], Seq[Attribute]) =>
MutableProjection,
+ offset: Int)
+ extends OffsetWindowFunctionFrameBase(
+ target, ordinal, expressions, inputSchema, newMutableProjection, offset) {
+
+ var selectedRow: UnsafeRow = null
+
+ override def prepare(rows: ExternalAppendOnlyUnsafeRowArray): Unit = {
+ super.prepare(rows)
+ if (inputIndex >= 0 && inputIndex < input.length) {
+ selectedRow = WindowFunctionFrame.getNextOrNull(inputIterator)
+ }
+ }
+
+ override def write(index: Int, current: InternalRow): Unit = {
+ if (index >= inputIndex && inputIndex < input.length && selectedRow !=
null) {
Review comment:
Thanks! Good eyesight!
----------------------------------------------------------------
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]