Skip to content

fix: preserve GROUPING SET dimensions with single-value filter #19285

Merged
jtuglu1 merged 2 commits into
apache:masterfrom
Shekharrajak:fix/13204-grouping-sets-single-value-filter
May 18, 2026
Merged

fix: preserve GROUPING SET dimensions with single-value filter #19285
jtuglu1 merged 2 commits into
apache:masterfrom
Shekharrajak:fix/13204-grouping-sets-single-value-filter

Conversation

@Shekharrajak
Copy link
Copy Markdown
Contributor

@Shekharrajak Shekharrajak commented Apr 9, 2026

Fixes #13204

Description

SELECT dim1, dim2, SUM(cnt)
FROM druid.foo
WHERE dim2 = 'a'
GROUP BY GROUPING SETS ( (dim1, dim2), (dim1) )

Before (incorrect):

dim1 | dim2 | SUM(cnt)
""   | a    | 1
"1"  | a    | 1
""   | a    | 1   -- should be null
"1"  | a    | 1   -- should be null

After (correct):

dim1 | dim2 | SUM(cnt)
""   | a    | 1
"1"  | a    | 1
""   | null | 1
"1"  | null | 1

Fixed Grouping.applyProject() to preserve non-literal dimensions (and literal dimensions referenced in non-empty
subtotals) when Subtotals.hasEffect() is true, preventing single-value filter dimensions from being dropped and
causing incorrect non-null values in GROUPING SET subtotal rows.

Release note

Fixed a bug where a SQL query using GROUPING SETS with a single-value WHERE filter on a grouped dimension would return
the filtered value instead of null in subtotal rows that exclude that dimension. For example, WHERE dim2 = 'a' GROUP
BY GROUPING SETS ((dim1, dim2), (dim1)) now correctly returns null for dim2 in the (dim1) subtotal rows instead of
repeating 'a'.


This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@FrankChen021
Copy link
Copy Markdown
Member

The changes LGTM, no correctness issues found.

Copy link
Copy Markdown
Member

@FrankChen021 FrankChen021 left a comment

Choose a reason for hiding this comment

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

I have reviewed the code for correctness, edge cases, concurrency, and integration risks; no issues found.


This is an automated review by Codex GPT-5

@Shekharrajak
Copy link
Copy Markdown
Contributor Author

Thanks @FrankChen021 for review. @a2l007 can you please have a look and lets merge it.

@Shekharrajak
Copy link
Copy Markdown
Contributor Author

@jtuglu1 Please have a look.

Copy link
Copy Markdown
Contributor

@jtuglu1 jtuglu1 left a comment

Choose a reason for hiding this comment

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

Can we add some quidem tests?

@Shekharrajak Shekharrajak force-pushed the fix/13204-grouping-sets-single-value-filter branch from 21560cb to 50ad101 Compare May 18, 2026 12:35
Copy link
Copy Markdown
Member

@FrankChen021 FrankChen021 left a comment

Choose a reason for hiding this comment

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

I have reviewed the updated code for correctness, edge cases, concurrency, lifecycle, and integration risks; no issues found.

Reviewed 3 of 3 changed files.


This is an automated review by Codex GPT-5.5

@jtuglu1 jtuglu1 self-requested a review May 18, 2026 16:00
@jtuglu1 jtuglu1 merged commit 12dcedf into apache:master May 18, 2026
38 checks passed
@github-actions github-actions Bot added this to the 38.0.0 milestone May 18, 2026
@Shekharrajak Shekharrajak deleted the fix/13204-grouping-sets-single-value-filter branch May 18, 2026 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect result format for queries with single value filters and GROUPING SET on the same dimension

3 participants