-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
[SPARK-17868][SQL] Do not use bitmasks during parsing and analysis of CUBE/ROLLUP/GROUPING SETS #15484
Closed
+474
−137
Closed
[SPARK-17868][SQL] Do not use bitmasks during parsing and analysis of CUBE/ROLLUP/GROUPING SETS #15484
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5456a95
remove bitmasks for grouping sets and use actual sets instead.
jiangxb1987 66efa00
update testcases.
jiangxb1987 bf5d419
update comments.
jiangxb1987 16bd22b
add test cases.
jiangxb1987 406060a
improve code quality.
jiangxb1987 481a6ac
refactor ResolveGroupingAnalytics
jiangxb1987 5587343
bugfix
jiangxb1987 4df9a42
add comment; simplify some case conditions.
jiangxb1987 ef3a733
add test cases for cubeExprs and rollupExprs
jiangxb1987 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 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 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 |
---|---|---|
|
@@ -492,33 +492,18 @@ class AstBuilder extends SqlBaseBaseVisitor[AnyRef] with Logging { | |
ctx: AggregationContext, | ||
selectExpressions: Seq[NamedExpression], | ||
query: LogicalPlan): LogicalPlan = withOrigin(ctx) { | ||
import ctx._ | ||
val groupByExpressions = expressionList(groupingExpressions) | ||
val groupByExpressions = expressionList(ctx.groupingExpressions) | ||
|
||
if (GROUPING != null) { | ||
if (ctx.GROUPING != null) { | ||
// GROUP BY .... GROUPING SETS (...) | ||
val expressionMap = groupByExpressions.zipWithIndex.toMap | ||
val numExpressions = expressionMap.size | ||
val mask = (1 << numExpressions) - 1 | ||
val masks = ctx.groupingSet.asScala.map { | ||
_.expression.asScala.foldLeft(mask) { | ||
case (bitmap, eCtx) => | ||
// Find the index of the expression. | ||
val e = typedVisit[Expression](eCtx) | ||
val index = expressionMap.find(_._1.semanticEquals(e)).map(_._2).getOrElse( | ||
throw new ParseException( | ||
s"$e doesn't show up in the GROUP BY list", ctx)) | ||
// 0 means that the column at the given index is a grouping column, 1 means it is not, | ||
// so we unset the bit in bitmap. | ||
bitmap & ~(1 << (numExpressions - 1 - index)) | ||
} | ||
} | ||
GroupingSets(masks, groupByExpressions, query, selectExpressions) | ||
val selectedGroupByExprs = | ||
ctx.groupingSet.asScala.map(_.expression.asScala.map(e => expression(e))) | ||
GroupingSets(selectedGroupByExprs, groupByExpressions, query, selectExpressions) | ||
} else { | ||
// GROUP BY .... (WITH CUBE | WITH ROLLUP)? | ||
val mappedGroupByExpressions = if (CUBE != null) { | ||
val mappedGroupByExpressions = if (ctx.CUBE != null) { | ||
Seq(Cube(groupByExpressions)) | ||
} else if (ROLLUP != null) { | ||
} else if (ctx.ROLLUP != null) { | ||
Seq(Rollup(groupByExpressions)) | ||
} else { | ||
groupByExpressions | ||
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. We don't check whether expression is in the GROUP BY list here, moved this to Analysis stage. 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. That is fine. |
||
|
Oops, something went wrong.
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.
I'd also write unit tests specifically for cubeExprs and rollupExprs
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.
Also I think you can just use subsets? e.g.
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.
I'm afraid we can't just map the
exprs
to a set because we want to keep the original order.