Skip to content

Prefer input columns over GROUP BY aliases - #60

Merged
osipovartem merged 1 commit into
embucket-sync-df55.0.0from
snowflake-group-by-input-precedence
Sep 4, 2026
Merged

Prefer input columns over GROUP BY aliases#60
osipovartem merged 1 commit into
embucket-sync-df55.0.0from
snowflake-group-by-input-precedence

Conversation

@osipovartem

Copy link
Copy Markdown
Collaborator

Which issue does this PR close?

  • Follow-up for Snowflake/PostgreSQL-compatible GROUP BY alias precedence on the embucket-sync-df55.0.0 branch.

Rationale for this change

When a bare GROUP BY identifier matches both an input column and a SELECT-list alias, SQL resolves it to the input column. DataFusion assembled the input and projected schemas before parsing the expression, so a qualified input field plus an unqualified alias with the same name produced a false ambiguity error.

What changes are included in this PR?

  • Resolve a bare GROUP BY identifier against the input schema first when that input column is unambiguous.
  • Keep the existing projected-schema path for alias-only names and non-bare expressions.
  • Use the selected schema consistently for normalization and placeholder inference.

Are these changes tested?

Yes. Added planner tests for both directions:

  • SELECT SUM(id) AS age FROM person GROUP BY age groups by the input person.age.
  • SELECT state AS age FROM person GROUP BY age reaches the expected non-aggregate validation instead of a false ambiguity.

Local verification:

cargo test -p datafusion-sql --test sql_integration
584 passed

cargo clippy -p datafusion-sql --all-targets --all-features -- -D warnings
passed

Are there any user-facing changes?

Yes. Queries with a SELECT alias that collides with an input column now follow SQL GROUP BY input-column precedence. There is no public API change.

@github-actions github-actions Bot added the sql label Sep 4, 2026
@osipovartem
osipovartem requested review from Vedin and rampage644 and removed request for rampage644 September 4, 2026 16:24
@osipovartem
osipovartem merged commit dc82fe5 into embucket-sync-df55.0.0 Sep 4, 2026
69 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant