-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: add the similar optimization function for bitwise negative #5516
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
| /// ~(A | B) ===> ~A & ~B | ||
| /// ~(~A) ===> A | ||
| /// For others, use Negative clause | ||
| pub fn negative_clause(expr: Expr) -> Expr { |
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.
I think, it deserves a better name.
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.
I think this is basically applying https://en.wikipedia.org/wiki/De_Morgan%27s_laws
Maybe we can call it distribute_negation?
|
Regarding tests: I have not noticed relevant tests for this segment of the code: https://github.com/apache/arrow-datafusion/blob/main/datafusion/optimizer/src/simplify_expressions/utils.rs#L249-#L273. Should we create a separate PR for this case to keep the symmetry? |
Yes please. Or even better I wonder if there is a way to avoid the duplication. Thank you @izveigor |
alamb
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.
| /// ~(A | B) ===> ~A & ~B | ||
| /// ~(~A) ===> A | ||
| /// For others, use Negative clause | ||
| pub fn negative_clause(expr: Expr) -> Expr { |
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.
I think this is basically applying https://en.wikipedia.org/wiki/De_Morgan%27s_laws
Maybe we can call it distribute_negation?
|
Converted to draft as it is waiting on other PRs and tests |
alamb
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.
Looks good -- thank you @izveigor
Which issue does this PR close?
Follow on to #5423
Rationale for this change
I propose to add the symmetric optimization function for bitwise negative.
Rules for bitwise negative in case of a binary expression are the same as the not clause:
~(A & B) ===> ~A | ~B
~(A | B) ===> ~A & ~B
~(~A) ===> A
What changes are included in this PR?
New optimization method for binary expressions with bitwise negative.
Are these changes tested?
After PR merge: #5511
Are there any user-facing changes?
Should increase execution speed