hvanhovell commented on a change in pull request #27440: [SPARK-27951][SQL] 
Support ANSI SQL NTH_VALUE window function
URL: https://github.com/apache/spark/pull/27440#discussion_r376786642
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowFunctionFrame.scala
 ##########
 @@ -157,6 +157,38 @@ final class OffsetWindowFunctionFrame(
   override def currentUpperBound(): Int = throw new 
UnsupportedOperationException()
 }
 
+class FixedOffsetWindowFunctionFrame(
+    target: InternalRow,
+    ordinal: Int,
+    expressions: Array[OffsetWindowFunction],
+    inputSchema: Seq[Attribute],
+    newMutableProjection: (Seq[Expression], Seq[Attribute]) => 
MutableProjection,
+    offset: Int)
+  extends OffsetWindowFunctionFrame(
+    target, ordinal, expressions, inputSchema, newMutableProjection, offset) {
+
+  override def prepare(rows: ExternalAppendOnlyUnsafeRowArray): Unit = {
+    input = rows
+    inputIndex = 0
+  }
+
+  override def write(index: Int, current: InternalRow): Unit = {
 
 Review comment:
   NTH_VALUE should return the same value for all rows in the window partition 
right? So why are you doing so much heavy lifting here? Everything can be 
computed in prepare.
   
   If you think about it, then this could also be treated as an unbounded 
window frame. You could even move this into the `UnboundedWindowFunctionFrame` 
if you add the update logic to the NTH_VALUE aggregate.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to