Skip to content
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

[SPARK-50749][SQL] Fix ordering bug in CommutativeExpression.gatherCommutative method #49392

Closed
wants to merge 2 commits into from

Conversation

utkarsh39
Copy link
Contributor

What changes were proposed in this pull request?

SPARK-49977 introduced a bug in the CommutativeExpression.gatherCommutative() method, changing the function's output order.
Consider the following concrete example:

val addExpression = Add(
  Literal(1),
  Add(
    Literal(2),
    Literal(3)
  )
)
val commutativeExpressions = addExpression.gatherCommutative(addExpression,
  { case Add(l, r, _) => Seq(l, r)})

Consider the output of the gatherCommutative method. SPARK-49977 introduced a bug that reversed the output order. This PR fixes the bug in gatherCommutative() to restore the original correct ordered output.

// Prior to [SPARK-49977](https://issues.apache.org/jira/browse/SPARK-49977) and after this fix
// commutativeExpressions -> Seq(Literal(1), Literal(2), Literal(3)))
// Post [SPARK-49977](https://issues.apache.org/jira/browse/SPARK-49977) and before this fix
// commutativeExpressions -> Seq(Literal(3), Literal(2), Literal(1)))

Why are the changes needed?

Fixing a bug

Does this PR introduce any user-facing change?

No

How was this patch tested?

Added a test

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

Generated-by: ChatGPT

@github-actions github-actions bot added the SQL label Jan 7, 2025
@zhengruifeng zhengruifeng changed the title [SPARK-50749] Fix ordering bug in CommutativeExpression.gatherCommutative method [SPARK-50749][SQL] Fix ordering bug in CommutativeExpression.gatherCommutative method Jan 7, 2025
@cloud-fan
Copy link
Contributor

The first commit passed CI (spark connect failure unrelated), and the new commit just moved the test. I'm merging it to master, thanks!

@cloud-fan cloud-fan closed this in f0fb8bf Jan 9, 2025
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.

2 participants