-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-25714][SQL][followup] improve the comment inside BooleanSimplification rule #22711
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
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -276,31 +276,37 @@ object BooleanSimplification extends Rule[LogicalPlan] with PredicateHelper { | |
| case a And b if a.semanticEquals(b) => a | ||
| case a Or b if a.semanticEquals(b) => a | ||
|
|
||
| // The following optimization is applicable only when the operands are not nullable, | ||
| // The following optimizations are applicable only when the operands are not nullable, | ||
| // since the three-value logic of AND and OR are different in NULL handling. | ||
| // See the chart: | ||
| // +---------+---------+---------+---------+ | ||
| // | p | q | p OR q | p AND q | | ||
| // | operand | operand | OR | AND | | ||
| // +---------+---------+---------+---------+ | ||
| // | TRUE | TRUE | TRUE | TRUE | | ||
| // | TRUE | FALSE | TRUE | FALSE | | ||
| // | TRUE | UNKNOWN | TRUE | UNKNOWN | | ||
| // | FALSE | TRUE | TRUE | FALSE | | ||
| // | FALSE | FALSE | FALSE | FALSE | | ||
| // | FALSE | UNKNOWN | UNKNOWN | FALSE | | ||
| // | UNKNOWN | TRUE | TRUE | UNKNOWN | | ||
| // | UNKNOWN | FALSE | UNKNOWN | FALSE | | ||
| // | UNKNOWN | UNKNOWN | UNKNOWN | UNKNOWN | | ||
| // +---------+---------+---------+---------+ | ||
|
|
||
| // (NULL And (NULL Or FALSE)) = NULL, but (NULL And FALSE) = FALSE. Thus, a can't be nullable. | ||
| case a And (b Or c) if !a.nullable && Not(a).semanticEquals(b) => And(a, c) | ||
| // (NULL And (FALSE Or NULL)) = NULL, but (NULL And FALSE) = FALSE. Thus, a can't be nullable. | ||
| case a And (b Or c) if !a.nullable && Not(a).semanticEquals(c) => And(a, b) | ||
| case (a Or b) And c if !a.nullable && a.semanticEquals(Not(c)) => And(b, c) | ||
| case (a Or b) And c if !b.nullable && b.semanticEquals(Not(c)) => And(a, c) | ||
| // ((NULL Or FALSE) And NULL) = NULL, but (FALSE And NULL) = FALSE. Thus, c can't be nullable. | ||
| case (a Or b) And c if !c.nullable && a.semanticEquals(Not(c)) => And(b, c) | ||
|
Contributor
Author
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.
|
||
| // ((FALSE Or NULL) And NULL) = NULL, but (FALSE And NULL) = FALSE. Thus, c can't be nullable. | ||
| case (a Or b) And c if !c.nullable && b.semanticEquals(Not(c)) => And(a, c) | ||
|
|
||
| // (NULL Or (NULL And TRUE)) = NULL, but (NULL Or TRUE) = TRUE. Thus, a can't be nullable. | ||
| case a Or (b And c) if !a.nullable && Not(a).semanticEquals(b) => Or(a, c) | ||
| // (NULL Or (TRUE And NULL)) = NULL, but (NULL Or TRUE) = TRUE. Thus, a can't be nullable. | ||
| case a Or (b And c) if !a.nullable && Not(a).semanticEquals(c) => Or(a, b) | ||
| case (a And b) Or c if !a.nullable && a.semanticEquals(Not(c)) => Or(b, c) | ||
| case (a And b) Or c if !b.nullable && b.semanticEquals(Not(c)) => Or(a, c) | ||
| // ((NULL And TRUE) Or NULL) = NULL, but (TRUE Or NULL) = TRUE. Thus, c can't be nullable. | ||
| case (a And b) Or c if !c.nullable && a.semanticEquals(Not(c)) => Or(b, c) | ||
| // ((TRUE And NULL) Or NULL) = NULL, but (TRUE Or NULL) = TRUE. Thus, c can't be nullable. | ||
| case (a And b) Or c if !c.nullable && b.semanticEquals(Not(c)) => Or(a, c) | ||
|
|
||
| // Common factor elimination for conjunction | ||
| case and @ (left And right) => | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
AND and OR is commutative, so we can reduce the entries in this table