Skip to content

Commit

Permalink
[SPARK-42609][CONNECT][TESTS] Add tests for grouping() and grouping_i…
Browse files Browse the repository at this point in the history
…d() 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 apache#40259 from amaliujia/rw-test-grouping-groupingset.

Authored-by: Rui Wang <rui.wang@databricks.com>
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
(cherry picked from commit 6874fd1)
Signed-off-by: Ruifeng Zheng <ruifengz@apache.org>
  • Loading branch information
amaliujia authored and dongjoon-hyun committed Mar 3, 2023
1 parent 530fb2c commit 3d09b40
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
Original file line number Diff line number Diff line change
@@ -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"
}
}]
}
}]
}
}
Binary file not shown.

0 comments on commit 3d09b40

Please sign in to comment.