This is an automated email from the ASF dual-hosted git repository.

ruifengz pushed a commit to branch branch-3.4
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/branch-3.4 by this push:
     new db5f6f6c341 [SPARK-42609][CONNECT][TESTS] Add tests for grouping() and 
grouping_id() functions
db5f6f6c341 is described below

commit db5f6f6c3418b3d331c1a8fcfbf93278980a63fb
Author: Rui Wang <[email protected]>
AuthorDate: Fri Mar 3 15:17:17 2023 +0800

    [SPARK-42609][CONNECT][TESTS] Add tests for grouping() and grouping_id() 
functions
    
    ### What changes were proposed in this pull request?
    
    Add tests for grouping() and grouping_id() functions.
    
    ### Why are the changes needed?
    
    Improve testing coverage.
    
    ### Does this PR introduce _any_ user-facing change?
    
    NO
    
    ### How was this patch tested?
    
    UT
    
    Closes #40259 from amaliujia/rw-test-grouping-groupingset.
    
    Authored-by: Rui Wang <[email protected]>
    Signed-off-by: Ruifeng Zheng <[email protected]>
    (cherry picked from commit 6874fd1b897680263ffbb3d06f716179a8e4c566)
    Signed-off-by: Ruifeng Zheng <[email protected]>
---
 .../apache/spark/sql/PlanGenerationTestSuite.scala |   6 +++
 .../grouping_and_grouping_id.explain               |   4 ++
 .../queries/grouping_and_grouping_id.json          |  57 +++++++++++++++++++++
 .../queries/grouping_and_grouping_id.proto.bin     | Bin 0 -> 138 bytes
 4 files changed, 67 insertions(+)

diff --git 
a/connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala
 
b/connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala
index 80ca5b43622..67dc92a7472 100644
--- 
a/connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala
+++ 
b/connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/PlanGenerationTestSuite.scala
@@ -1966,6 +1966,12 @@ class PlanGenerationTestSuite
     simple.cube("a", "b").count()
   }
 
+  test("grouping and grouping_id") {
+    simple
+      .cube("a", "b")
+      .agg(fn.grouping("a"), fn.grouping("b"), fn.grouping_id("a", "b"))
+  }
+
   test("pivot") {
     simple.groupBy(Column("id")).pivot("a", Seq(1, 2, 
3)).agg(functions.count(Column("b")))
   }
diff --git 
a/connector/connect/common/src/test/resources/query-tests/explain-results/grouping_and_grouping_id.explain
 
b/connector/connect/common/src/test/resources/query-tests/explain-results/grouping_and_grouping_id.explain
new file mode 100644
index 00000000000..3b7d6fb2b70
--- /dev/null
+++ 
b/connector/connect/common/src/test/resources/query-tests/explain-results/grouping_and_grouping_id.explain
@@ -0,0 +1,4 @@
+Aggregate [a#0, b#0, spark_grouping_id#0L], [a#0, b#0, 
cast((shiftright(spark_grouping_id#0L, 1) & 1) as tinyint) AS grouping(a)#0, 
cast((shiftright(spark_grouping_id#0L, 0) & 1) as tinyint) AS grouping(b)#0, 
spark_grouping_id#0L AS grouping_id(a, b)#0L]
++- Expand [[id#0L, a#0, b#0, a#0, b#0, 0], [id#0L, a#0, b#0, a#0, null, 1], 
[id#0L, a#0, b#0, null, b#0, 2], [id#0L, a#0, b#0, null, null, 3]], [id#0L, 
a#0, b#0, a#0, b#0, spark_grouping_id#0L]
+   +- Project [id#0L, a#0, b#0, a#0 AS a#0, b#0 AS b#0]
+      +- LocalRelation <empty>, [id#0L, a#0, b#0]
diff --git 
a/connector/connect/common/src/test/resources/query-tests/queries/grouping_and_grouping_id.json
 
b/connector/connect/common/src/test/resources/query-tests/queries/grouping_and_grouping_id.json
new file mode 100644
index 00000000000..07bbd315a5f
--- /dev/null
+++ 
b/connector/connect/common/src/test/resources/query-tests/queries/grouping_and_grouping_id.json
@@ -0,0 +1,57 @@
+{
+  "common": {
+    "planId": "1"
+  },
+  "aggregate": {
+    "input": {
+      "common": {
+        "planId": "0"
+      },
+      "localRelation": {
+        "schema": "struct\u003cid:bigint,a:int,b:double\u003e"
+      }
+    },
+    "groupType": "GROUP_TYPE_CUBE",
+    "groupingExpressions": [{
+      "unresolvedAttribute": {
+        "unparsedIdentifier": "a"
+      }
+    }, {
+      "unresolvedAttribute": {
+        "unparsedIdentifier": "b"
+      }
+    }],
+    "aggregateExpressions": [{
+      "unresolvedFunction": {
+        "functionName": "grouping",
+        "arguments": [{
+          "unresolvedAttribute": {
+            "unparsedIdentifier": "a"
+          }
+        }]
+      }
+    }, {
+      "unresolvedFunction": {
+        "functionName": "grouping",
+        "arguments": [{
+          "unresolvedAttribute": {
+            "unparsedIdentifier": "b"
+          }
+        }]
+      }
+    }, {
+      "unresolvedFunction": {
+        "functionName": "grouping_id",
+        "arguments": [{
+          "unresolvedAttribute": {
+            "unparsedIdentifier": "a"
+          }
+        }, {
+          "unresolvedAttribute": {
+            "unparsedIdentifier": "b"
+          }
+        }]
+      }
+    }]
+  }
+}
\ No newline at end of file
diff --git 
a/connector/connect/common/src/test/resources/query-tests/queries/grouping_and_grouping_id.proto.bin
 
b/connector/connect/common/src/test/resources/query-tests/queries/grouping_and_grouping_id.proto.bin
new file mode 100644
index 00000000000..88b3f059313
Binary files /dev/null and 
b/connector/connect/common/src/test/resources/query-tests/queries/grouping_and_grouping_id.proto.bin
 differ


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to