-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-21055][SQL] replace grouping__id with grouping_id() #18270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
36ff72a
eplace grouping__id with grouping_id()
cenyuhai 2c6ed67
remove delimiter
cenyuhai 059d486
Add order by
cenyuhai e4d6d48
Add order by
cenyuhai 1202bfa
generate group-analytics result
cenyuhai eac37f0
change code as xiaoli said
cenyuhai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1414,6 +1414,19 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| ).map(i => Row(i._1, i._2, i._3))) | ||
| } | ||
|
|
||
| test("SPARK-21055 replace grouping__id: Wrong Result for Rollup #1") { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of adding a new one, you can just make a change on the existing one. test("SPARK-8976 Wrong Result for Rollup #1") {
Seq("grouping_id()", "grouping__id").foreach { gid =>
checkAnswer(sql(
s"SELECT count(*) AS cnt, key % 5, $gid FROM src GROUP BY key%5 WITH ROLLUP"),
Seq(
(113, 3, 0),
(91, 0, 0),
(500, null, 1),
(84, 1, 0),
(105, 2, 0),
(107, 4, 0)
).map(i => Row(i._1, i._2, i._3)))
}
} |
||
| checkAnswer(sql( | ||
| "SELECT count(*) AS cnt, key % 5, grouping__id FROM src GROUP BY key%5 WITH ROLLUP"), | ||
| Seq( | ||
| (113, 3, 0), | ||
| (91, 0, 0), | ||
| (500, null, 1), | ||
| (84, 1, 0), | ||
| (105, 2, 0), | ||
| (107, 4, 0) | ||
| ).map(i => Row(i._1, i._2, i._3))) | ||
| } | ||
|
|
||
| test("SPARK-8976 Wrong Result for Rollup #2") { | ||
| checkAnswer(sql( | ||
| """ | ||
|
|
@@ -1435,6 +1448,27 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| ).map(i => Row(i._1, i._2, i._3, i._4))) | ||
| } | ||
|
|
||
| test("SPARK-21055 replace grouping__id: Wrong Result for Rollup #2") { | ||
| checkAnswer(sql( | ||
| """ | ||
| |SELECT count(*) AS cnt, key % 5 AS k1, key-5 AS k2, grouping__id AS k3 | ||
| |FROM src GROUP BY key%5, key-5 | ||
| |WITH ROLLUP ORDER BY cnt, k1, k2, k3 LIMIT 10 | ||
| """.stripMargin), | ||
| Seq( | ||
| (1, 0, 5, 0), | ||
| (1, 0, 15, 0), | ||
| (1, 0, 25, 0), | ||
| (1, 0, 60, 0), | ||
| (1, 0, 75, 0), | ||
| (1, 0, 80, 0), | ||
| (1, 0, 100, 0), | ||
| (1, 0, 140, 0), | ||
| (1, 0, 145, 0), | ||
| (1, 0, 150, 0) | ||
| ).map(i => Row(i._1, i._2, i._3, i._4))) | ||
| } | ||
|
|
||
| test("SPARK-8976 Wrong Result for Rollup #3") { | ||
| checkAnswer(sql( | ||
| """ | ||
|
|
@@ -1456,6 +1490,27 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| ).map(i => Row(i._1, i._2, i._3, i._4))) | ||
| } | ||
|
|
||
| test("SPARK-21055 replace grouping__id: Wrong Result for Rollup #3") { | ||
| checkAnswer(sql( | ||
| """ | ||
| |SELECT count(*) AS cnt, key % 5 AS k1, key-5 AS k2, grouping__id AS k3 | ||
| |FROM (SELECT key, key%2, key - 5 FROM src) t GROUP BY key%5, key-5 | ||
| |WITH ROLLUP ORDER BY cnt, k1, k2, k3 LIMIT 10 | ||
| """.stripMargin), | ||
| Seq( | ||
| (1, 0, 5, 0), | ||
| (1, 0, 15, 0), | ||
| (1, 0, 25, 0), | ||
| (1, 0, 60, 0), | ||
| (1, 0, 75, 0), | ||
| (1, 0, 80, 0), | ||
| (1, 0, 100, 0), | ||
| (1, 0, 140, 0), | ||
| (1, 0, 145, 0), | ||
| (1, 0, 150, 0) | ||
| ).map(i => Row(i._1, i._2, i._3, i._4))) | ||
| } | ||
|
|
||
| test("SPARK-8976 Wrong Result for CUBE #1") { | ||
| checkAnswer(sql( | ||
| "SELECT count(*) AS cnt, key % 5, grouping_id() FROM src GROUP BY key%5 WITH CUBE"), | ||
|
|
@@ -1469,6 +1524,19 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| ).map(i => Row(i._1, i._2, i._3))) | ||
| } | ||
|
|
||
| test("SPARK-21055 replace grouping__id: Wrong Result for CUBE #1") { | ||
| checkAnswer(sql( | ||
| "SELECT count(*) AS cnt, key % 5, grouping__id FROM src GROUP BY key%5 WITH CUBE"), | ||
| Seq( | ||
| (113, 3, 0), | ||
| (91, 0, 0), | ||
| (500, null, 1), | ||
| (84, 1, 0), | ||
| (105, 2, 0), | ||
| (107, 4, 0) | ||
| ).map(i => Row(i._1, i._2, i._3))) | ||
| } | ||
|
|
||
| test("SPARK-8976 Wrong Result for CUBE #2") { | ||
| checkAnswer(sql( | ||
| """ | ||
|
|
@@ -1490,6 +1558,27 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| ).map(i => Row(i._1, i._2, i._3, i._4))) | ||
| } | ||
|
|
||
| test("SPARK-21055 replace grouping__id: Wrong Result for CUBE #2") { | ||
| checkAnswer(sql( | ||
| """ | ||
| |SELECT count(*) AS cnt, key % 5 AS k1, key-5 AS k2, grouping__id AS k3 | ||
| |FROM (SELECT key, key%2, key - 5 FROM src) t GROUP BY key%5, key-5 | ||
| |WITH CUBE ORDER BY cnt, k1, k2, k3 LIMIT 10 | ||
| """.stripMargin), | ||
| Seq( | ||
| (1, null, -3, 2), | ||
| (1, null, -1, 2), | ||
| (1, null, 3, 2), | ||
| (1, null, 4, 2), | ||
| (1, null, 5, 2), | ||
| (1, null, 6, 2), | ||
| (1, null, 12, 2), | ||
| (1, null, 14, 2), | ||
| (1, null, 15, 2), | ||
| (1, null, 22, 2) | ||
| ).map(i => Row(i._1, i._2, i._3, i._4))) | ||
| } | ||
|
|
||
| test("SPARK-8976 Wrong Result for GroupingSet") { | ||
| checkAnswer(sql( | ||
| """ | ||
|
|
@@ -1511,6 +1600,27 @@ class SQLQuerySuite extends QueryTest with SQLTestUtils with TestHiveSingleton { | |
| ).map(i => Row(i._1, i._2, i._3, i._4))) | ||
| } | ||
|
|
||
| test("SPARK-21055 replace grouping__id: Wrong Result for GroupingSet") { | ||
| checkAnswer(sql( | ||
| """ | ||
| |SELECT count(*) AS cnt, key % 5 AS k1, key-5 AS k2, grouping__id AS k3 | ||
| |FROM (SELECT key, key%2, key - 5 FROM src) t GROUP BY key%5, key-5 | ||
| |GROUPING SETS (key%5, key-5) ORDER BY cnt, k1, k2, k3 LIMIT 10 | ||
| """.stripMargin), | ||
| Seq( | ||
| (1, null, -3, 2), | ||
| (1, null, -1, 2), | ||
| (1, null, 3, 2), | ||
| (1, null, 4, 2), | ||
| (1, null, 5, 2), | ||
| (1, null, 6, 2), | ||
| (1, null, 12, 2), | ||
| (1, null, 14, 2), | ||
| (1, null, 15, 2), | ||
| (1, null, 22, 2) | ||
| ).map(i => Row(i._1, i._2, i._3, i._4))) | ||
| } | ||
|
|
||
| ignore("SPARK-10562: partition by column with mixed case name") { | ||
| withTable("tbl10562") { | ||
| val df = Seq(2012 -> "a").toDF("Year", "val") | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you only commit
group-analytics.sql.out? You should also commit modifiedgroup-analytics.sql.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for your tips