feat: support grouping() and grouping_id() indicator functions#4815
Open
andygrove wants to merge 1 commit into
Open
feat: support grouping() and grouping_id() indicator functions#4815andygrove wants to merge 1 commit into
andygrove wants to merge 1 commit into
Conversation
Add SQL file test coverage for grouping/grouping_id with ROLLUP, CUBE, and GROUPING SETS, and mark both as supported in the expressions guide. These are Unevaluable expressions that the analyzer rewrites into arithmetic over the virtual spark_grouping_id column, so the constituent operators and expressions (ExpandExec, Cast, BitwiseAnd, ShiftRight, Literal) already run natively in Comet.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Which issue does this PR close?
Closes #4814.
Rationale for this change
The
grouping()andgrouping_id()indicator functions used withROLLUP,CUBE, andGROUPING SETSwere marked as unsupported in the expressions guide. In practice they areUnevaluableexpressions that Spark's analyzer rewrites before physical planning:grouping(col)becomesCast(BitwiseAnd(ShiftRight(spark_grouping_id, n-1-i), 1L), ByteType)grouping_id()becomes a reference to thespark_grouping_idvirtual columnEvery constituent piece is already supported by Comet: the
ExpandExecoperator thatROLLUP/CUBE/GROUPING SETSlower to, plusCast,BitwiseAnd,ShiftRight, andLiteral. As a result these queries already run natively end-to-end, so no Scala serde or Rust work is required. This PR adds the missing test coverage and updates the documentation to reflect the actual support level.What changes are included in this PR?
spark/src/test/resources/sql-tests/expressions/aggregate/grouping.sqlcoveringgrouping(col)andgrouping_id()withCUBE,ROLLUP, andGROUPING SETS, multi-column grouping, the explicit-columngrouping_id(a, b)form, combinedgrouping+grouping_idusage, use inHAVING, and NULL input data.groupingandgrouping_idas supported (✅) indocs/source/user-guide/latest/expressions.md.This change was scaffolded using the
implement-comet-expressionskill.How are these changes tested?
The new SQL file test runs each query through both Spark and Comet in the default
querymode, which asserts that the whole plan executes natively on Comet (no fallback) and that results match Spark exactly. All queries pass: