-
Notifications
You must be signed in to change notification settings - Fork 773
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
feat(optimizer): simplify_equality #2281
Conversation
1 + x + 1 = 3 + 1; | ||
x = 2; | ||
|
||
x - INTERVAL 1 DAY = CAST('2021-01-01' AS DATE); |
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.
what would happen if it's
x - interval 1 day = cast(y as date)
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.
Nothing. The right side must be a date literal.
return expression | ||
|
||
return expression.__class__( | ||
this=a.copy(), expression=INVERSE_OPS[l.__class__](this=r.copy(), expression=b.copy()) |
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.
are these copies needed?
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 shit sorry i hit merge.
I'm not sure.
In general, I copy when creating a new expression using child nodes from an existing tree. When do you?
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.
in the optimizer, i only copy when i have to, because it's mutation heavy and expensive,
in generator, where the contract is idempotency and no mutations, i copy
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.
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.
Agree on copy
being a bit redundant here: It seems like we're dropping the expression
arg in this return statement anyway & a
and b
are not associated with r
's AST, so this completely replaces the AST corresponding to the input expression.
We have expressions like this:
This optimization, plus the previous operations, gives: