-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-17849] [SQL] Fix NPE problem when using grouping sets #15416
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
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,10 +298,11 @@ class Analyzer( | |
| case other => Alias(other, other.toString)() | ||
| } | ||
|
|
||
| val nonNullBitmask = x.bitmasks.reduce(_ & _) | ||
| val nonNullBitmask = ~ x.bitmasks.reduce(_ | _) | ||
|
Contributor
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. Could you remove the '~' here, and use
Author
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. Do you mean |
||
|
|
||
| val attrLength = groupByAliases.length | ||
| val expandedAttributes = groupByAliases.zipWithIndex.map { case (a, idx) => | ||
| a.toAttribute.withNullability((nonNullBitmask & 1 << idx) == 0) | ||
| a.toAttribute.withNullability((nonNullBitmask & 1 << (attrLength - idx - 1)) == 0) | ||
| } | ||
|
|
||
| val expand = Expand(x.bitmasks, groupByAliases, expandedAttributes, gid, x.child) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2189,6 +2189,24 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext { | |
| } | ||
| } | ||
|
|
||
| test("SPARK-17849: grouping set throws NPE") { | ||
|
Contributor
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. maybe we can move this into SQLQueryTestSuite, by creating a new grouping_set.q file??
Author
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. @rxin done |
||
| val data = Seq( | ||
| ("1", "2", "3", 1), | ||
| ("4", "5", "6", 1), | ||
| ("7", "8", "9", 1) | ||
| ) | ||
| data.toDF("a", "b", "c", "d").createOrReplaceTempView("point_table") | ||
| checkAnswer( | ||
| sql("select a, b, c, count(d) from point_table group by a, b, c GROUPING SETS (())"), | ||
| Row(null, null, null, 3) :: Nil) | ||
| checkAnswer( | ||
| sql("select a, b, c, count(d) from point_table group by a, b, c GROUPING SETS ((a))"), | ||
| Row("1", null, null, 1) :: | ||
| Row("4", null, null, 1) :: | ||
| Row("7", null, null, 1) :: Nil) | ||
| } | ||
|
|
||
|
|
||
| test("hash function") { | ||
| val df = Seq(1 -> "a", 2 -> "b").toDF("i", "j") | ||
| withTempView("tbl") { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Bit manipulation magic is hard to follow. This is should be documented better. Could you add a line or two to explain how the bitmasks are structured?
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.
+1
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.
Ok, I'll do it.
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.
@hvanhovell @rxin comments are added