Skip to content

Revert "[SPARK-47895][SQL] group by alias should be idempotent" #50567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

mihailotim-db
Copy link
Contributor

@mihailotim-db mihailotim-db commented Apr 11, 2025

What changes were proposed in this pull request?

This PR reverts #50461 because it introduces a correctness issue by replacing an Alias with incorrect literal. A followup will be made with a different way to fix this issue.

Why are the changes needed?

In the below example, alias abc is replaced with 2 resulting in 2 rows instead of correct 3.
Before erronous PR:
image

After erronous PR:
image

Does this PR introduce any user-facing change?

User now sees an error message instead of an incorrect result.

How was this patch tested?

Added a test case to check for this behavior in the future

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

No

@github-actions github-actions bot added the SQL label Apr 11, 2025
Copy link
Contributor

@mihailom-db mihailom-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, but we still need to fix the problem of reanalysis for aliases

@dongjoon-hyun
Copy link
Member

cc @cloud-fan

.getOrElse((u, -1))

trimAliases(result) match {
// HACK ALERT: If the expanded grouping expression is an integer literal, don't use it
Copy link
Contributor

Choose a reason for hiding this comment

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

This hack only works if the resolved integer literal is the root expression, which may not be true here.

Good catch!

@cloud-fan
Copy link
Contributor

thanks, merging to master/4.0!

@cloud-fan cloud-fan closed this in 8718eba Apr 14, 2025
cloud-fan pushed a commit that referenced this pull request Apr 14, 2025
### What changes were proposed in this pull request?
This PR reverts #50461 because it introduces a correctness issue by replacing an `Alias` with incorrect literal. A followup will be made with a different way to fix this issue.

### Why are the changes needed?
In the below example, alias `abc` is replaced with `2` resulting in 2 rows instead of correct 3.
Before erronous PR:
![image](https://github.com/user-attachments/assets/dcc98323-369d-4f5e-b0ad-de5b76ffc5c3)

After erronous PR:
![image](https://github.com/user-attachments/assets/31c24125-6654-48f8-9b55-40a6a667ed23)

### Does this PR introduce _any_ user-facing change?
User now sees an error message instead of an incorrect result.

### How was this patch tested?
Added a test case to check for this behavior in the future

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

Closes #50567 from mihailotim-db/mihailotim-db/revert_group_by.

Authored-by: Mihailo Timotic <[email protected]>
Signed-off-by: Wenchen Fan <[email protected]>
(cherry picked from commit 8718eba)
Signed-off-by: Wenchen Fan <[email protected]>
@dongjoon-hyun
Copy link
Member

For the record, the JIRA ID seems to be reused mistakenly in the original PR and this revert unfortunately. SPARK-47895 was group by all ... instead of group by alias ....

$ git log --oneline | grep SPARK-47895
8718eba1f6f Revert "[SPARK-47895][SQL] group by alias should be idempotent"
02db87282da [SPARK-47895][SQL] group by alias should be idempotent
b5bb75ca240 [SPARK-47895][SQL] group by all should be idempotent

Could you confirm that, @mihailotim-db ?

@mihailotim-db
Copy link
Contributor Author

Correct, but the root of the issue is the same so I guess that is why they reused the same ticket

@dongjoon-hyun
Copy link
Member

Correct, but the root of the issue is the same so I guess that is why they reused the same ticket

Thank you for the comment. It seems that there is misunderstanding here if it's done intentionally.

To @mihailotim-db and @mihailom-db . I just want to give you the context in order to prevent future accident like the following.

02db87282da [SPARK-47895][SQL] group by alias should be idempotent
b5bb75ca240 [SPARK-47895][SQL] group by all should be idempotent

ASF JIRA IDs have Fixed Versions field. Even for the direct follow-up PRs, we cannot reuse JIRA IDs when the original patch is released already. It's because the original PR and the follow-up PR cannot have the same Fixed Versions field. Please make it sure that ASF JIRA ID is different from any internal customer ticket systems.

Since this reverting PR itself has no problem, let me post the same comment on the original PR, too.

@mihailotim-db
Copy link
Contributor Author

@dongjoon-hyun Good to know, thanks!

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.

4 participants