Skip to content

Conversation

@costin
Copy link
Member

@costin costin commented Apr 3, 2021

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.

@costin costin requested review from astefan, bpintea and matriv April 3, 2021 09:55
@elasticmachine elasticmachine added the Team:QL (Deprecated) Meta label for query languages team label Apr 3, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (Team:QL)

Copy link
Member Author

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.

Copy link

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?

Copy link
Member Author

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.

Copy link
Member Author

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.

costin added 3 commits April 3, 2021 20:44
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.
@costin costin force-pushed the ql/fix-canonicalize branch from ed3fbc8 to 45e17c4 Compare April 3, 2021 19:04
for (Expression exp : exps) {
canonical.add(exp.canonical());
}
return canonical;
Copy link

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());

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@costin costin merged commit e202e54 into elastic:master Apr 5, 2021
@costin costin deleted the ql/fix-canonicalize branch April 5, 2021 11:49
costin added a commit to costin/elasticsearch that referenced this pull request Apr 5, 2021
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.
costin added a commit that referenced this pull request Apr 5, 2021
…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)) {
Copy link
Contributor

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/EQL EQL querying :Analytics/SQL SQL querying >enhancement Team:QL (Deprecated) Meta label for query languages team v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants