-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-24424][SQL] Support ANSI-SQL compliant syntax for GROUPING SET #21813
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
Conversation
|
Test build #93260 has finished for PR 21813 at commit
|
|
retest this please |
|
Test build #93266 has finished for PR 21813 at commit
|
| aggregationExprs: Seq[NamedExpression], | ||
| child: LogicalPlan): LogicalPlan = { | ||
|
|
||
|
|
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.
this blank lines can be removed?
| fromClause | ||
| : FROM relation (',' relation)* lateralView* pivotClause? | ||
| ; | ||
|
|
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.
revert this?
| child: LogicalPlan): LogicalPlan = { | ||
| val gid = AttributeReference(VirtualColumn.groupingIdName, IntegerType, false)() | ||
|
|
||
| val finalGroupByExpressions = if (groupByExprs == Nil) { |
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.
Shouldn't we do this in the branch of case x: GroupingSets if x.expressions.forall(_.resolved) =>? I think this constructAggregate method is also used by other clauses like Cube and Rollup.
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.
@viirya Yeah.. so for cube and rollup, we will always have groupByExprs setup right ? So i felt its better to keep the code consolidated here in this function. What do u think ?
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. Mind to add a comment on this like SPARK-24424: this only happens for ANSI-SQL compliant syntax for GROUPING SET?
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.
@viirya Sure will do.
|
|
||
| val originalPlan2 = GroupingSets(Seq(Seq(), Seq(unresolved_a), Seq(unresolved_a, unresolved_b)), | ||
| Nil, r1, | ||
| Seq(unresolved_a, unresolved_b, UnresolvedAlias(count(unresolved_c)))) |
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.
hmm, I think originalPlan2 looks the same as originalPlan?
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.
@viirya Thanks.. u right. I will remove it.
|
Test build #93291 has finished for PR 21813 at commit
|
|
Test build #93299 has finished for PR 21813 at commit
|
| HAVING GROUPING__ID > 1; | ||
|
|
||
| -- Group sets without explicit group by | ||
| SELECT grouping(c1) FROM (VALUES ('x', 'a', 10), ('y', 'b', 20)) AS t (c1, c2, c3) GROUP BY c1,c2 GROUPING SETS (c1,c2); |
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.
Doesn't this have explicit group by?
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.
@viirya sorry.. yeah.. i will remove the explicit group by cols.. I had it for testing but forgot to take them out.
| FROM (VALUES (1, 2), (3, 2)) t(c1, c2) | ||
| GROUP BY GROUPING SETS ( ( c1 ), ( c1, c2 ) ) | ||
| HAVING col2 IS NOT NULL | ||
| ORDER BY -col1; |
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've manually verified the results should be correct.
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.
@viirya Sorry Simon.. do i have to do something for this comment ?
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.
Not at all. @dilipbiswal :-)
| // can be null. In such case, we derive the groupByExprs from the user supplied values for | ||
| // grouping sets. | ||
| val finalGroupByExpressions = if (groupByExprs == Nil) { | ||
| selectedGroupByExprs.flatten.foldLeft(Seq.empty[Expression]) { (result, currentExpr) => |
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.
What if GROUP BY GROUPING SETS (())? Is it a valid query?
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.
@viirya No. We should be getting an error as we don't have a group by specification. I had tried this scenario against db2 to double check.
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.
Can we have a test case for it too?
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.
@viirya Yeah.. was already adding it .. knew u would ask :-)
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.
@dilipbiswal Thanks! :-)
|
Test build #93304 has finished for PR 21813 at commit
|
|
Test build #93313 has finished for PR 21813 at commit
|
gatorsmile
left a comment
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.
LGTM
|
Thanks! Merged to master. |
|
Thank you very much @gatorsmile @viirya |
What changes were proposed in this pull request?
Enhances the parser and analyzer to support ANSI compliant syntax for GROUPING SET. As part of this change we derive the grouping expressions from user supplied groupings in the grouping sets clause.
How was this patch tested?
Added tests in SQLQueryTestSuite and ResolveGroupingAnalyticsSuite.
Please review http://spark.apache.org/contributing.html before opening a pull request.