Skip to content

Commit 2b806bb

Browse files
committed
Add NULL tests
1 parent e120562 commit 2b806bb

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

sql/core/src/test/scala/org/apache/spark/sql/DataFrameWindowSuite.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,24 @@ class DataFrameWindowSuite extends QueryTest with SharedSQLContext {
292292
Row("b", 3, 8, 32),
293293
Row("b", 2, 4, 8)))
294294
}
295+
296+
test("null inputs") {
297+
val df = Seq(("a", 1), ("a", 1), ("a", 2), ("a", 2), ("b", 4), ("b", 3), ("b", 2))
298+
.toDF("key", "value")
299+
val window = Window.orderBy()
300+
checkAnswer(
301+
df.select(
302+
$"key",
303+
$"value",
304+
avg(lit(null)).over(window),
305+
sum(lit(null)).over(window)),
306+
Seq(
307+
Row("a", 1, null, null),
308+
Row("a", 1, null, null),
309+
Row("a", 2, null, null),
310+
Row("a", 2, null, null),
311+
Row("b", 4, null, null),
312+
Row("b", 3, null, null),
313+
Row("b", 2, null, null)))
314+
}
295315
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/WindowQuerySuite.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,19 @@ class WindowQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleto
227227
Row("Manufacturer#5", "almond azure blanched chiffon midnight", 23, 315.9225931564038, 315.9225931564038, 46, 99807.08486666666, -0.9978877469246935, -5664.856666666666)))
228228
// scalastyle:on
229229
}
230+
231+
test("null arguments") {
232+
checkAnswer(sql("""
233+
|select p_mfgr, p_name, p_size,
234+
|sum(null) over(distribute by p_mfgr sort by p_name) as sum,
235+
|avg(null) over(distribute by p_mfgr sort by p_name) as avg
236+
|from part
237+
""".stripMargin),
238+
sql("""
239+
|select p_mfgr, p_name, p_size,
240+
|null as sum,
241+
|null as avg
242+
|from part
243+
""".stripMargin))
244+
}
230245
}

0 commit comments

Comments
 (0)