Skip to content

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

Open
Shekharrajak wants to merge 1 commit intoapache:masterfrom
Shekharrajak:fix/13204-grouping-sets-single-value-filter
Open

fix: preserve GROUPING SET dimensions with single-value filter #19285
Shekharrajak wants to merge 1 commit intoapache: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.

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

1 participant