dongjoon-hyun commented on a change in pull request #31325:
URL: https://github.com/apache/spark/pull/31325#discussion_r564159569
##########
File path:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameWindowFunctionsSuite.scala
##########
@@ -1044,4 +1044,30 @@ class DataFrameWindowFunctionsSuite extends QueryTest
Row(Seq(-0.0f, 0.0f), Row(-0.0d, Double.NaN), Seq(Row(-0.0d,
Double.NaN)), 2),
Row(Seq(0.0f, -0.0f), Row(0.0d, Double.NaN), Seq(Row(0.0d, 0.0/0.0)),
2)))
}
+
+ test("SPARK-34227: WindowFunctionFrame should clear its states during
preparation") {
+ // This creates a single partition dataframe with 3 records:
+ // "a", 0, null
+ // "a", 1, "x"
+ // "b", 0, null
+ val df = spark.range(0, 3, 1, 1).select(
+ when($"id" < 2, lit("a")).otherwise(lit("b")).as("key"),
+ ($"id" % 2).cast("int").as("order"),
+ when($"id" % 2 === 0, lit(null)).otherwise(lit("x")).as("value"))
+
+ val window1 = Window.partitionBy($"key").orderBy($"order")
+ .rowsBetween(Window.unboundedPreceding, Window.unboundedFollowing)
+ val window2 = Window.partitionBy($"key").orderBy($"order")
+ .rowsBetween(Window.unboundedPreceding, Window.currentRow)
+ checkAnswer(
+ df.select(
+ $"key",
+ $"order",
+ nth_value($"value", 1, ignoreNulls = true).over(window1),
+ nth_value($"value", 1, ignoreNulls = true).over(window2)),
+ Seq(
+ Row("a", 0, "x", null),
+ Row("a", 1, "x", "x"),
+ Row("b", 0, null, null)))
Review comment:
Oh, nice finding.
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/window/WindowFunctionFrame.scala
##########
@@ -299,13 +309,10 @@ class UnboundedOffsetWindowFunctionFrame(
assert(offset > 0)
override def prepare(rows: ExternalAppendOnlyUnsafeRowArray): Unit = {
- input = rows
- if (offset > input.length) {
+ if (offset > rows.length) {
Review comment:
+1 for @imback82 's suggestion.
----------------------------------------------------------------
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]