Skip to content

fix(query): return semantic error for invalid grouping()#19594

Open
sundy-li wants to merge 7 commits intodatabendlabs:mainfrom
sundy-li:fix/issue-19554-grouping-semantic-error-20260323-03
Open

fix(query): return semantic error for invalid grouping()#19594
sundy-li wants to merge 7 commits intodatabendlabs:mainfrom
sundy-li:fix/issue-19554-grouping-semantic-error-20260323-03

Conversation

@sundy-li
Copy link
Copy Markdown
Member

@sundy-li sundy-li commented Mar 23, 2026

I hereby agree to the terms of the CLA available at: https://docs.databend.com/dev/policies/cla/

Summary

Tests

  • Unit Test
  • Logic Test
  • Benchmark Test
  • No Test - Explain why

Type of change

  • Bug Fix (non-breaking change which fixes an issue)
  • New Feature (non-breaking change which adds functionality)
  • Breaking Change (fix or feature that could cause existing functionality not to work as expected)
  • Documentation Update
  • Refactoring
  • Performance Improvement
  • Other (please describe):

Validation

  • cargo test -p databend-query --test it sql::planner::semantic::type_check::test_invalid_grouping_returns_semantic_error -- --exact
  • cargo test -p databend-query --test it sql::planner::semantic::type_check -- --nocapture
  • cargo fmt --all --check
  • cargo clippy -p databend-common-expression -p databend-common-sql --lib -- -D warnings

Added sqllogictest coverage in tests/sqllogictests/suites/duckdb/sql/aggregate/group/group_by_grouping_sets.test, but did not run the standalone sqllogictest harness locally.


This change is Reviewable

@github-actions github-actions bot added the pr-bugfix this PR patches a bug in codebase label Mar 23, 2026
@sundy-li sundy-li added the agent-reviewable Ready for agent review label Mar 23, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 31daed9aad

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@sundy-li
Copy link
Copy Markdown
Member Author

The current fix is still incomplete for invalid grouping() outside the rewrite paths.

bind_where() only rejects AggregateFunction / window nodes, so grouping() is still treated as an ordinary scalar function there. bind_qualify() has the same problem when it delegates to GroupingChecker, because GroupingChecker explicitly leaves FunctionCall(grouping) untouched.

That means queries like SELECT count() FROM students WHERE GROUPING() = 0 GROUP BY course can still get past planning as a dummy scalar grouping call instead of returning a semantic error, and can still hit the dummy grouping implementation later.

Please extend the validation/rewrite so the non-rewritten clauses are covered as well (at least WHERE, and likely QUALIFY), and add regression coverage for one of those forms.

@sundy-li sundy-li added the agent-changed Changed by agent label Mar 24, 2026
@sundy-li sundy-li removed the agent-changed Changed by agent label Mar 24, 2026
sundy-li

This comment was marked as outdated.

sundy-li

This comment was marked as outdated.

sundy-li

This comment was marked as outdated.

@sundy-li sundy-li added the agent-changed Changed by agent label Mar 24, 2026
@sundy-li sundy-li added agent-changed Changed by agent and removed agent-changed Changed by agent labels Mar 24, 2026
@sundy-li sundy-li added agent-changed Changed by agent agent-approved Approved by agent and removed agent-changed Changed by agent agent-reviewable Ready for agent review labels Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-approved Approved by agent pr-bugfix this PR patches a bug in codebase

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: invalid GROUPING() query panics during constant folding instead of returning semantic error

1 participant