-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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-43095][SQL] Avoid Once strategy's idempotence is broken for batch: Infer Filters
#40742
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,13 +66,15 @@ trait ConstraintHelper { | |
val predicates = constraints.filterNot(_.isInstanceOf[IsNotNull]) | ||
predicates.foreach { | ||
case eq @ EqualTo(l: Attribute, r: Attribute) => | ||
val candidateConstraints = predicates - eq | ||
// Also remove EqualNullSafe with the same l and r to avoid Once strategy's idempotence | ||
// is broken. l = r and l <=> r can infer l <=> l and r <=> r which is useless. | ||
val candidateConstraints = predicates - eq - EqualNullSafe(l, r) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. But the current situation is like this: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah got it. Let's add a code comment to explain it with this example. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you explain it a bit more about why it makes the optimizer not idempotent? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For example:
After
And run
The right side constraints:
Join condition is:
Based on these constraints, the inferred result is:
|
||
inferredConstraints ++= replaceConstraints(candidateConstraints, l, r) | ||
inferredConstraints ++= replaceConstraints(candidateConstraints, r, l) | ||
case eq @ EqualTo(l @ Cast(_: Attribute, _, _, _), r: Attribute) => | ||
inferredConstraints ++= replaceConstraints(predicates - eq, r, l) | ||
inferredConstraints ++= replaceConstraints(predicates - eq - EqualNullSafe(l, r), r, l) | ||
case eq @ EqualTo(l: Attribute, r @ Cast(_: Attribute, _, _, _)) => | ||
inferredConstraints ++= replaceConstraints(predicates - eq, l, r) | ||
inferredConstraints ++= replaceConstraints(predicates - eq - EqualNullSafe(l, r), l, r) | ||
case _ => // No inference | ||
} | ||
inferredConstraints -- constraints | ||
|
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.
not related to this PR, but shall we match
Equality
here?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.
Yes. It seems ok.