-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-53155][SQL] Global lower agggregation should not be replaced with a project #51884
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the JIRA issue, is this bug starting at Spark 3.4? Or, is it a long-standing bug which we have before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, the issue seems there since RemoveRedundantAggregates was introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SPARK-33122 seems to introduce this at Spark 3.2.0.
|
Thank you, @viirya . cc @peter-toth , too. |
dongjoon-hyun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1, LGTM.
9c626df to
808a35c
Compare
| .groupBy()(Literal(1).as("col1"), Literal(2).as("col2"), Literal(3).as("col3")) | ||
| .groupBy($"col1")(max($"col1")) | ||
| .analyze | ||
| val expected = relation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expected = query?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, as seems it doesn't look like necessary so I didn't change this to save another CI round. Thank you.
…ith a project This patch fixes the optimization rule `RemoveRedundantAggregates`. The optimizer rule `RemoveRedundantAggregates` removes redundant lower aggregation from a query plan and replace it with a project of referred non-aggregate expressions. However, if the removed aggregation is a global one, that is not correct because a project is different with a global aggregation in semantics. For example, if the input relation is empty, a project might be optimized to an empty relation, while a global aggregation will return a single row. Yes, this fixes a user-facing bug. Previously, a global aggregation under another aggregation might be treated as redundant and replaced as a project with non-aggregation expressions. If the input relation is empty, the replacement is incorrect and might produce incorrect result. This patch adds a new unit test to show the difference. Unit test, manual test. No Closes #51884 from viirya/fix_remove_redundant_agg. Authored-by: Liang-Chi Hsieh <[email protected]> Signed-off-by: Liang-Chi Hsieh <[email protected]> (cherry picked from commit 3aa8c9d) Signed-off-by: Liang-Chi Hsieh <[email protected]>
…ith a project This patch fixes the optimization rule `RemoveRedundantAggregates`. The optimizer rule `RemoveRedundantAggregates` removes redundant lower aggregation from a query plan and replace it with a project of referred non-aggregate expressions. However, if the removed aggregation is a global one, that is not correct because a project is different with a global aggregation in semantics. For example, if the input relation is empty, a project might be optimized to an empty relation, while a global aggregation will return a single row. Yes, this fixes a user-facing bug. Previously, a global aggregation under another aggregation might be treated as redundant and replaced as a project with non-aggregation expressions. If the input relation is empty, the replacement is incorrect and might produce incorrect result. This patch adds a new unit test to show the difference. Unit test, manual test. No Closes #51884 from viirya/fix_remove_redundant_agg. Authored-by: Liang-Chi Hsieh <[email protected]> Signed-off-by: Liang-Chi Hsieh <[email protected]> (cherry picked from commit 3aa8c9d) Signed-off-by: Liang-Chi Hsieh <[email protected]>
|
Thanks @dongjoon-hyun @peter-toth Merged to master/4.0/3.5. |
|
The CI of branch-4.0 failed on https://github.com/apache/spark/actions/runs/16808660184/job/47607970234 This patch doesn't touch any AQE or shuffle stuffs. I also verified it locally and the test passed without issue. Seems just a flaky test. For branch-3.5, all tests were passed but just documentation build failed: https://github.com/apache/spark/actions/runs/16808722611/job/47608228583 I think it is not related too. |
…ith a project This patch fixes the optimization rule `RemoveRedundantAggregates`. The optimizer rule `RemoveRedundantAggregates` removes redundant lower aggregation from a query plan and replace it with a project of referred non-aggregate expressions. However, if the removed aggregation is a global one, that is not correct because a project is different with a global aggregation in semantics. For example, if the input relation is empty, a project might be optimized to an empty relation, while a global aggregation will return a single row. Yes, this fixes a user-facing bug. Previously, a global aggregation under another aggregation might be treated as redundant and replaced as a project with non-aggregation expressions. If the input relation is empty, the replacement is incorrect and might produce incorrect result. This patch adds a new unit test to show the difference. Unit test, manual test. No Closes apache#51884 from viirya/fix_remove_redundant_agg. Authored-by: Liang-Chi Hsieh <[email protected]> Signed-off-by: Liang-Chi Hsieh <[email protected]> (cherry picked from commit 776b68f) Signed-off-by: Liang-Chi Hsieh <[email protected]>
What changes were proposed in this pull request?
This patch fixes the optimization rule
RemoveRedundantAggregates.Why are the changes needed?
The optimizer rule
RemoveRedundantAggregatesremoves redundant lower aggregation from a query plan and replace it with a project of referred non-aggregate expressions. However, if the removed aggregation is a global one, that is not correct because a project is different with a global aggregation in semantics.For example, if the input relation is empty, a project might be optimized to an empty relation, while a global aggregation will return a single row.
Does this PR introduce any user-facing change?
Yes, this fixes a user-facing bug. Previously, a global aggregation under another aggregation might be treated as redundant and replaced as a project with non-aggregation expressions. If the input relation is empty, the replacement is incorrect and might produce incorrect result. This patch adds a new unit test to show the difference.
How was this patch tested?
Unit test, manual test.
Was this patch authored or co-authored using generative AI tooling?
No