Skip to content

Conversation

@mihailoale-db
Copy link
Contributor

@mihailoale-db mihailoale-db commented Dec 30, 2025

What changes were proposed in this pull request?

In this PR I propose to trim aliases from grouping and aggregate expressions before handling grouping analytics. This is needed for the following query:

SELECT col1 AS k2 FROM values(1) GROUP BY CUBE(k2)

Here we have col1 in the single-pass whereas in the fixed-point we have col1 AS k2 before constructing an Aggregate in ResolveGroupingAnalytics. Change removes the AS k2 part and keeps the compatibility between single-pass and fixed-point analyzers without changing outputs (analyzed plans are different, only names).
The change also inlines the behavior with regular aggregates (without grouping analytics). In other words:

SELECT col1 + col2 AS a FROM VALUES(1,2) GROUP BY a

Here col1 + col2 should be the grouping expression (as it is) and we inline the behaviors.

Why are the changes needed?

To keep the compatibility between fixed-point and single-pass analyzers.

Does this PR introduce any user-facing change?

No.

How was this patch tested?

Changed tests.

Was this patch authored or co-authored using generative AI tooling?

No.

@github-actions
Copy link

JIRA Issue Information

=== Improvement SPARK-54871 ===
Summary: Trim aliases from grouping and aggregate expressions before handling grouping analytics
Assignee: None
Status: Open
Affected: ["4.1.0"]


This comment was automatically generated by GitHub Actions

@github-actions github-actions bot added the SQL label Dec 30, 2025
Copy link
Contributor

@mihailotim-db mihailotim-db left a comment

Choose a reason for hiding this comment

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

LGTM. Let's also mention in the PR description that this is not only for single-pass analyzer, but would also be consistent with how normal aggregates currently work:
image

@mihailoale-db
Copy link
Contributor Author

@mihailotim-db Done! @cloud-fan PTAL when you find time. Thanks!

@mihailoale-db mihailoale-db force-pushed the trimaliasesgroupinganalytics branch from 8ebc485 to 3225517 Compare December 31, 2025 17:47
@cloud-fan
Copy link
Contributor

thanks, merging to master!

@cloud-fan cloud-fan closed this in 0353790 Jan 3, 2026
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.

3 participants