Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test
  • Loading branch information
cxzl25 committed Jun 26, 2025
commit 14a7f2da72f8403a8d80d0391b396223950ef6c2
Original file line number Diff line number Diff line change
Expand Up @@ -1619,4 +1619,21 @@ class DataFrameWindowFunctionsSuite extends QueryTest
}
}
}

test("SPARK-49386: Window spill with more than the inMemoryThreshold and spillSizeThreshold") {
val df = Seq((1, "1"), (2, "2"), (1, "3"), (2, "4")).toDF("key", "value")
val window = Window.partitionBy($"key").orderBy($"value")

withSQLConf(SQLConf.WINDOW_EXEC_BUFFER_IN_MEMORY_THRESHOLD.key -> "1",
SQLConf.WINDOW_EXEC_BUFFER_SPILL_THRESHOLD.key -> Int.MaxValue.toString) {
assertNotSpilled(sparkContext, "select") {
df.select($"key", sum("value").over(window)).collect()
}
withSQLConf(SQLConf.WINDOW_EXEC_BUFFER_SIZE_SPILL_THRESHOLD.key -> "1") {
assertSpilled(sparkContext, "select") {
df.select($"key", sum("value").over(window)).collect()
}
}
}
}
}
94 changes: 94 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/JoinSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,100 @@ class JoinSuite extends QueryTest with SharedSparkSession with AdaptiveSparkPlan
}
}

test("SPARK-49386: test SortMergeJoin (with spill by size threshold)") {
withSQLConf(SQLConf.AUTO_BROADCASTJOIN_THRESHOLD.key -> "1",
SQLConf.SORT_MERGE_JOIN_EXEC_BUFFER_IN_MEMORY_THRESHOLD.key -> "0",
SQLConf.SORT_MERGE_JOIN_EXEC_BUFFER_SPILL_THRESHOLD.key -> Int.MaxValue.toString,
SQLConf.SORT_MERGE_JOIN_EXEC_BUFFER_SIZE_SPILL_THRESHOLD.key -> "1") {

assertSpilled(sparkContext, "inner join") {
checkAnswer(
sql("SELECT * FROM testData JOIN testData2 ON key = a where key = 2"),
Row(2, "2", 2, 1) :: Row(2, "2", 2, 2) :: Nil
)
}

// LEFT SEMI JOIN without bound condition does not spill
assertNotSpilled(sparkContext, "left semi join") {
checkAnswer(
sql("SELECT * FROM testData LEFT SEMI JOIN testData2 ON key = a WHERE key = 2"),
Row(2, "2") :: Nil
)
}

// LEFT ANTI JOIN without bound condition does not spill
assertNotSpilled(sparkContext, "left anti join") {
checkAnswer(
sql("SELECT * FROM testData LEFT ANTI JOIN testData2 ON key = a WHERE key = 2"),
Nil
)
}

val expected = new ListBuffer[Row]()
expected.appendAll(Seq(
Row(1, "1", 1, 1), Row(1, "1", 1, 2),
Row(2, "2", 2, 1), Row(2, "2", 2, 2),
Row(3, "3", 3, 1), Row(3, "3", 3, 2))
)
for (i <- 4 to 100) {
expected.append(Row(i, i.toString, null, null))
}

assertSpilled(sparkContext, "left outer join") {
checkAnswer(
sql(
"""
|SELECT
| big.key, big.value, small.a, small.b
|FROM
| testData big
|LEFT OUTER JOIN
| testData2 small
|ON
| big.key = small.a
""".stripMargin),
expected.toSeq
)
}

assertSpilled(sparkContext, "right outer join") {
checkAnswer(
sql(
"""
|SELECT
| big.key, big.value, small.a, small.b
|FROM
| testData2 small
|RIGHT OUTER JOIN
| testData big
|ON
| big.key = small.a
""".stripMargin),
expected.toSeq
)
}

// FULL OUTER JOIN still does not use [[ExternalAppendOnlyUnsafeRowArray]]
// so should not cause any spill
assertNotSpilled(sparkContext, "full outer join") {
checkAnswer(
sql(
"""
|SELECT
| big.key, big.value, small.a, small.b
|FROM
| testData2 small
|FULL OUTER JOIN
| testData big
|ON
| big.key = small.a
""".stripMargin),
expected.toSeq
)
}
}
}

test("outer broadcast hash join should not throw NPE") {
withTempView("v1", "v2") {
withSQLConf(SQLConf.WHOLESTAGE_CODEGEN_ENABLED.key -> "true") {
Expand Down