-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add negations to all text predicates #2559
Add negations to all text predicates #2559
Conversation
|
92a8cd4
to
e1d748a
Compare
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.
Thank you for the huge contribution! Can you please sign the CLA?
I only did a quick pass on the PR, but in general, looks good to me. Left a few comments/questions:
...h-backend-testutils/src/main/java/org/janusgraph/diskstorage/indexing/IndexProviderTest.java
Show resolved
Hide resolved
janusgraph-driver/src/main/java/org/janusgraph/core/attribute/Text.java
Outdated
Show resolved
Hide resolved
janusgraph-lucene/src/main/java/org/janusgraph/diskstorage/lucene/LuceneIndex.java
Show resolved
Hide resolved
90186c6
to
2a4cc05
Compare
janusgraph-driver/src/main/java/org/janusgraph/core/attribute/Text.java
Outdated
Show resolved
Hide resolved
janusgraph-driver/src/main/java/org/janusgraph/core/attribute/Text.java
Outdated
Show resolved
Hide resolved
2a4cc05
to
841f7f6
Compare
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.
Thank you, LGTM 👍
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.
Just on question out of curiosity: Wouldn´t be better to just wrap the predicate into a not(...)
?
@@ -0,0 +1,474 @@ | |||
// Copyright 2017 JanusGraph Authors |
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.
2011
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.
Just saw this, updated the Copyright on the new file to 2021.
@farodin91 See discussions in #1868. Briefly speaking, not(has(key, predicate)) is not semantically equivalent to has(key, ~predicate). |
https://tinkerpop.apache.org/docs/current/reference/#a-note-on-predicates |
I see it mentions that UPDATE: After seeing the latest reply from @WheresMyStapler, I realized I might have understood @farodin91 wrong. I was thinking about the case |
@farodin91, wrapping the predicate in the
Since this PR implements .negate for all the text predicates, this now functions:
But, only when using Elasticsearch, or in-memory if full scans are enabled. |
Thank you @WheresMyStapler ! |
Yes! |
Signed-off-by: Andrew Sheppard <[email protected]>
841f7f6
to
bc65403
Compare
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. Thank you @WheresMyStapler !
@farodin91 Will you review above answers from @WheresMyStapler ? |
That's great. Thank you implementing this feature. |
@Override | ||
public boolean test(Object value, Object condition) { | ||
this.preevaluate(value, condition); | ||
return value != null && evaluateRaw(value.toString(), (String) condition); |
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.
@porunov / @li-boxuan / @farodin91
Sorry to bring you all back to this PR, but after using this some more locally, I ran into a case that was not covered here regarding null values / missing properties:
gremlin> g.V().has('missingField', textNotRegex('.*'))
==>v[86040]
gremlin> g.V(86040L).propertyMap()
==>[]
gremlin> g.V(86040L).has('missingField', textNotRegex('.*'))
gremlin>
Should the negation tests remove the != null tests, or just simply short circuit if null?
return value == null || evaluateRaw(value.toString(), (String) condition);
The question I really have is how to interpret the tinkerpop docs:
has(key,predicate): Remove the traverser if its element does not have a key value that satisfies the bi-predicate. For more information on predicates
Since the key doesnt have a value at all, which predicate evaluation is correct? ES or JG?
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 went ahead and created a new PR for this change (#2593). If you think .has(X, Y)
assumes .has(X).has(X, Y)
, feel free to close it.
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.
gremlin> g.V().has('missingField', textNotRegex('.*'))
==>v[86040]
I believe above is wrong. I actually suspect this will fail for TinkerPop test suite, since I don't believe this is TinkerPop-aligned. A related discussion is on #1868
My understanding is:
g.V().has('missingField', textNotRegex('.*')) == g.V().has('missingField', not(textRegex('.*'))) == g.V().has('missingField').has('missingField', not(textRegex('.*'))) != g.V().not(has('missingField', textRegex('.*')))
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.
Perfect. I updated my new PR to change the negated query in ES from mustNot(predicate)
to must(exists(field), mustNot(predicate))
, which aligns the predicate evaluations:
gremlin> g.V().has('missingField', textNotRegex('.*'))
gremlin>
gremlin> g.V(86040L).propertyMap()
==>[]
gremlin> g.V(86040L).has('missingField', textNotRegex('.*'))
gremlin>
The predicates added in JanusGraph#2559 were not supported by `JanusGraphPSerializer` and could thus not be used when connecting via remote to JanusGraph Server. Fixes JanusGraph#4275 Signed-off-by: Florian Hockmann <[email protected]>
The predicates added in #2559 were not supported by `JanusGraphPSerializer` and could thus not be used when connecting via remote to JanusGraph Server. Fixes #4275 Signed-off-by: Florian Hockmann <[email protected]>
The predicates added in #2559 were not supported by `JanusGraphPSerializer` and could thus not be used when connecting via remote to JanusGraph Server. Fixes #4275 Signed-off-by: Florian Hockmann <[email protected]> (cherry picked from commit 5b906fe)
The predicates added in #2559 were not supported by `JanusGraphPSerializer` and could thus not be used when connecting via remote to JanusGraph Server. Fixes #4275 Signed-off-by: Florian Hockmann <[email protected]> (cherry picked from commit 5b906fe)
Text.CONTAINS_PHRASE
, which exposes Elastic'smatch_phrase
queryText.CONTAINS_FUZZY.evaluateRaw(...)
and Elastic'sfuzziness:"AUTO"
Thank you for contributing to JanusGraph!
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
master
)?For code changes:
For documentation related changes: