-
Notifications
You must be signed in to change notification settings - Fork 25.7k
QL: Make canonical form take into account children #71266
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
|
Pinging @elastic/es-ql (Team:QL) |
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.
Changed the order of hashing to encourage caching / similarities of values that have the same datatype.
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.
Is there backwards compatibility concerns?
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.
Made Negatable accept any kind of expression not just functions. This way Not can be negated without special handling.
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.
Canonicalize after negation to avoid recreating the trees twice since canonical already handles normalization and ordering.
Currently the canonical form takes into account only the node itself and not its children. For commutative cases this creates subtle issues in that the children are swapped based on their canonical form but not canonicalize and thus semantic comparison fail. This PR fixes that by taking into account the canonical children and, for commutative expressions, applies semantic ordering. In the process, improve handling of nested negated expressions.
ed3fbc8 to
45e17c4
Compare
| for (Expression exp : exps) { | ||
| canonical.add(exp.canonical()); | ||
| } | ||
| return canonical; |
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.
Possible to use more Java 8 syntax?
return exps.stream()
.map(Expression::canonical)
.collect(Collectors.toList());
astefan
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.
LGTM
Currently the canonical form takes into account only the node itself and not its children. For commutative cases this creates subtle issues in that the children are swapped based on their canonical form but not canonicalize and thus semantic comparison fail. This PR fixes that by taking into account the canonical children and, for commutative expressions, applies semantic ordering. In the process, improve handling of nested negated expressions.
…1287) Currently the canonical form takes into account only the node itself and not its children. For commutative cases this creates subtle issues in that the children are swapped based on their canonical form but not canonicalize and thus semantic comparison fail. This PR fixes that by taking into account the canonical children and, for commutative expressions, applies semantic ordering. In the process, improve handling of nested negated expressions.
| } | ||
| List<Expression> canonicalChildren = Expressions.canonicalize(children()); | ||
| // check if replacement is really needed | ||
| if (children().equals(canonicalChildren)) { |
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.
If it's possible, for the future, maybe we should move this handling inside the replaceChildren()
Currently the canonical form takes into account only the node itself and
not its children.
For commutative cases this creates subtle issues in that the children
are swapped based on their canonical form but not canonicalize and thus
semantic comparison fail.
This PR fixes that by taking into account the canonical children and,
for commutative expressions, applies semantic ordering.
In the process, improve handling of nested negated expressions.