Github user smurakozi commented on a diff in the pull request:
https://github.com/apache/spark/pull/20045#discussion_r158304105
--- Diff:
sql/core/src/test/scala/org/apache/spark/sql/DataFrameWindowFunctionsSuite.scala
---
@@ -32,6 +32,217 @@ import org.apache.spark.unsafe.types.CalendarInterval
class DataFrameWindowFunctionsSuite extends QueryTest with
SharedSQLContext {
import testImplicits._
+ test("Window partitionBy cardinality, no order by") {
+ val df = Seq(("a", 1), ("a", 2), ("b", 4), ("b", 4)).toDF("key",
"value")
+
+ checkAnswer(
+ df.select(
+ sum("value").over(),
+ sum("value").over(Window.partitionBy("key")),
+ sum("value").over(Window.partitionBy("key", "value")),
+ sum("value").over(Window.partitionBy("value", "key"))),
+ Row(11, 3, 1, 1) :: Row(11, 3, 2, 2) :: Row(11, 8, 8, 8) :: Row(11,
8, 8, 8) :: Nil)
+ }
+
+ test("Null value in partition key") {
+ val df = Seq(("a", 1), ("a", 2), (null, 4), (null, 8)).toDF("key",
"value")
+
+ checkAnswer(
+ df.select(
+ 'value,
+ sum("value").over(Window.partitionBy("key"))),
+ Row(1, 3) :: Row(2, 3) :: Row(4, 12) :: Row(8, 12) :: Nil)
+ }
+
+ test("Same partitionBy multiple times") {
+ val df = Seq(("a", 1), ("a", 2), ("b", 4), ("b", 8)).toDF("key",
"value")
+
+ checkAnswer(
+ df.select(
+ sum("value").over(Window.partitionBy("key", "key"))),
+ Row(3) :: Row(3) :: Row(12) :: Row(12) :: Nil)
+ }
+
+ test("Multiple orderBy clauses") {
+ val df = Seq(("a", "x", 1), ("a", "y", 2), ("b", "y", 3), ("b", "x",
4)).toDF("k1", "k2", "v")
+
+ checkAnswer(
+ df.select(
+ 'v,
+ lead("v", 1).over(Window.orderBy("k1", "k2")),
+ lead("v", 1).over(Window.orderBy("k2", "k1"))),
+ Row(1, 2, 4) :: Row(4, 3, 2) :: Row(2, 4, 3) :: Row(3, null, null)
:: Nil)
+ }
+
+ test("Multiple orderBy clauses with desc") {
+ val df = Seq(("a", "x", 1), ("a", "y", 2), ("b", "y", 3), ("b", "x",
4)).toDF("k1", "k2", "v")
+
+ checkAnswer(
+ df.select(
+ 'v,
+ lead("v", 1).over(Window.orderBy($"k1".desc, $"k2")),
+ lead("v", 1).over(Window.orderBy($"k1", $"k2".desc)),
+ lead("v", 1).over(Window.orderBy($"k1".desc, $"k2"))),
--- End diff --
It should be desc, desc, thanks for catching it.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]