Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,11 @@ class Analyzer(
case other => Alias(other, other.toString)()
}

val nonNullBitmask = x.bitmasks.reduce(_ & _)
val nonNullBitmask = ~ x.bitmasks.reduce(_ | _)

@hvanhovell hvanhovell Oct 10, 2016

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Copy link
Copy Markdown
Author

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.

Copy link
Copy Markdown
Author

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you remove the '~' here, and use (nonNullBitmask & (1 << (attrLength - idx - 1))) == 1?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean ((nonNullBitmask >> (attrLength - idx - 1)) & 1) == 1? We can only test on 0 if we left shift 1, right? @davies


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)
Expand Down
18 changes: 18 additions & 0 deletions sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2189,6 +2189,24 @@ class SQLQuerySuite extends QueryTest with SharedSQLContext {
}
}

test("SPARK-17849: grouping set throws NPE") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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??

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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") {
Expand Down