-
Notifications
You must be signed in to change notification settings - Fork 598
fix(core): normalize boolean range predicates in Gremlin filters #2991
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
Open
contrueCT
wants to merge
9
commits into
apache:master
Choose a base branch
from
contrueCT:task/fix-2934
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
98fef9a
fix: support boolean range predicates in condition query
contrueCT dc441b6
test: cover boolean range query edge cases
contrueCT 4cd2049
fix(test): align boolean range regression coverage
contrueCT d92050f
fix(core): normalize boolean range predicates
contrueCT a07f43f
test(core): expand boolean range edge coverage
contrueCT ce8a4bb
fix(core): address boolean predicate review feedback
contrueCT 9679866
test(core): fix nullable boolean predicate coverage
contrueCT bec076d
test(core): complete nullable boolean edge fixtures
contrueCT 3abba15
fix(core): refine boolean predicate handling
contrueCT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7117,6 +7117,165 @@ public void testQueryEdgeWithNullablePropertyInCompositeIndex() { | |
| Assert.assertEquals(1, (int) el.get(0).value("id")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQueryEdgeByBooleanRangePredicate() { | ||
| HugeGraph graph = graph(); | ||
| initStrikeIndex(); | ||
| graph.schema().indexLabel("strikeByArrested").onE("strike").secondary() | ||
| .by("arrested").create(); | ||
|
|
||
| Vertex louise = graph.addVertex(T.label, "person", "name", "Louise", | ||
| "city", "Beijing", "age", 21); | ||
| Vertex sean = graph.addVertex(T.label, "person", "name", "Sean", | ||
| "city", "Beijing", "age", 23); | ||
| long current = System.currentTimeMillis(); | ||
| louise.addEdge("strike", sean, "id", 1, | ||
| "timestamp", current, "place", "park", | ||
| "tool", "shovel", "reason", "jeer", | ||
| "arrested", false); | ||
| louise.addEdge("strike", sean, "id", 2, | ||
| "timestamp", current + 1, "place", "street", | ||
| "tool", "shovel", "reason", "jeer", | ||
| "arrested", true); | ||
|
|
||
| List<Edge> hasLtEdges = graph.traversal().E() | ||
| .has("arrested", P.lt(true)) | ||
| .toList(); | ||
| Assert.assertEquals(1, hasLtEdges.size()); | ||
| Assert.assertEquals(1, (int) hasLtEdges.get(0).value("id")); | ||
|
|
||
| List<Edge> whereEdges = graph.traversal().E() | ||
| .where(__.has("arrested", P.lt(true))) | ||
| .toList(); | ||
| Assert.assertEquals(1, whereEdges.size()); | ||
| Assert.assertEquals(1, (int) whereEdges.get(0).value("id")); | ||
|
|
||
| List<Edge> matchEdges = graph.traversal().E() | ||
| .match(__.as("start") | ||
| .where(__.has("arrested", | ||
| P.lt(true))) | ||
| .as("matched")) | ||
| .<Edge>select("matched") | ||
| .toList(); | ||
| Assert.assertEquals(1, matchEdges.size()); | ||
| Assert.assertEquals(1, (int) matchEdges.get(0).value("id")); | ||
|
|
||
| List<Edge> hasNeqTrueEdges = graph.traversal().E() | ||
| .has("arrested", P.neq(true)) | ||
| .toList(); | ||
| Assert.assertEquals(1, hasNeqTrueEdges.size()); | ||
| Assert.assertEquals(1, (int) hasNeqTrueEdges.get(0).value("id")); | ||
|
|
||
| List<Edge> hasNeqFalseEdges = graph.traversal().E() | ||
| .has("arrested", P.neq(false)) | ||
| .toList(); | ||
| Assert.assertEquals(1, hasNeqFalseEdges.size()); | ||
| Assert.assertEquals(2, (int) hasNeqFalseEdges.get(0).value("id")); | ||
|
|
||
| List<Edge> hasLteFalseEdges = graph.traversal().E() | ||
| .has("arrested", P.lte(false)) | ||
| .toList(); | ||
| Assert.assertEquals(1, hasLteFalseEdges.size()); | ||
| Assert.assertEquals(1, (int) hasLteFalseEdges.get(0).value("id")); | ||
|
|
||
| List<Edge> hasGtFalseEdges = graph.traversal().E() | ||
| .has("arrested", P.gt(false)) | ||
| .toList(); | ||
| Assert.assertEquals(1, hasGtFalseEdges.size()); | ||
| Assert.assertEquals(2, (int) hasGtFalseEdges.get(0).value("id")); | ||
|
|
||
| List<Edge> hasGteTrueEdges = graph.traversal().E() | ||
| .has("arrested", P.gte(true)) | ||
| .toList(); | ||
| Assert.assertEquals(1, hasGteTrueEdges.size()); | ||
| Assert.assertEquals(2, (int) hasGteTrueEdges.get(0).value("id")); | ||
|
|
||
| List<Edge> hasGteFalseEdges = graph.traversal().E() | ||
| .has("arrested", P.gte(false)) | ||
| .toList(); | ||
| Assert.assertEquals(2, hasGteFalseEdges.size()); | ||
| Set<Integer> gteFalseIds = new HashSet<>(); | ||
| for (Edge edge : hasGteFalseEdges) { | ||
| gteFalseIds.add(edge.value("id")); | ||
| } | ||
| Assert.assertEquals(ImmutableSet.of(1, 2), gteFalseIds); | ||
|
|
||
| List<Edge> hasLteTrueEdges = graph.traversal().E() | ||
| .has("arrested", P.lte(true)) | ||
| .toList(); | ||
| Assert.assertEquals(2, hasLteTrueEdges.size()); | ||
| Set<Integer> lteTrueIds = new HashSet<>(); | ||
| for (Edge edge : hasLteTrueEdges) { | ||
| lteTrueIds.add(edge.value("id")); | ||
| } | ||
| Assert.assertEquals(ImmutableSet.of(1, 2), lteTrueIds); | ||
|
|
||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 缺少
|
||
| Assert.assertEquals(0, graph.traversal().E() | ||
| .has("arrested", P.lt(false)) | ||
| .toList().size()); | ||
| Assert.assertEquals(0, graph.traversal().E() | ||
| .has("arrested", P.gt(true)) | ||
| .toList().size()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQueryEdgeByBooleanRangePredicateWithoutNullableProperty() { | ||
| HugeGraph graph = graph(); | ||
| initStrikeIndex(); | ||
| graph.schema().indexLabel("strikeByHurt").onE("strike").secondary() | ||
| .by("hurt").create(); | ||
|
|
||
| Vertex louise = graph.addVertex(T.label, "person", "name", "Louise", | ||
| "city", "Beijing", "age", 21); | ||
| Vertex sean = graph.addVertex(T.label, "person", "name", "Sean", | ||
| "city", "Beijing", "age", 23); | ||
| long current = System.currentTimeMillis(); | ||
| louise.addEdge("strike", sean, "id", 1, | ||
| "timestamp", current, "place", "park", | ||
| "tool", "shovel", "reason", "jeer", | ||
| "hurt", false, "arrested", false); | ||
| louise.addEdge("strike", sean, "id", 2, | ||
| "timestamp", current + 1, "place", "street", | ||
| "tool", "shovel", "reason", "jeer", | ||
| "hurt", true, "arrested", true); | ||
| louise.addEdge("strike", sean, "id", 3, | ||
| "timestamp", current + 2, "place", "mall", | ||
| "tool", "shovel", "reason", "jeer", | ||
| "arrested", false); | ||
|
|
||
| List<Edge> gteFalseEdges = graph.traversal().E() | ||
| .has("hurt", P.gte(false)) | ||
| .toList(); | ||
| Assert.assertEquals(2, gteFalseEdges.size()); | ||
| Set<Integer> gteFalseIds = new HashSet<>(); | ||
| for (Edge edge : gteFalseEdges) { | ||
| gteFalseIds.add(edge.value("id")); | ||
| } | ||
| Assert.assertEquals(ImmutableSet.of(1, 2), gteFalseIds); | ||
|
|
||
| List<Edge> lteTrueEdges = graph.traversal().E() | ||
| .has("hurt", P.lte(true)) | ||
| .toList(); | ||
| Assert.assertEquals(2, lteTrueEdges.size()); | ||
| Set<Integer> lteTrueIds = new HashSet<>(); | ||
| for (Edge edge : lteTrueEdges) { | ||
| lteTrueIds.add(edge.value("id")); | ||
| } | ||
| Assert.assertEquals(ImmutableSet.of(1, 2), lteTrueIds); | ||
|
|
||
| List<Edge> lteFalseEdges = graph.traversal().E() | ||
| .has("hurt", P.lte(false)) | ||
| .toList(); | ||
| Assert.assertEquals(1, lteFalseEdges.size()); | ||
| Assert.assertEquals(1, (int) lteFalseEdges.get(0).value("id")); | ||
|
|
||
| List<Edge> neqTrueEdges = graph.traversal().E() | ||
| .has("hurt", P.neq(true)) | ||
| .toList(); | ||
| Assert.assertEquals(1, neqTrueEdges.size()); | ||
| Assert.assertEquals(1, (int) neqTrueEdges.get(0).value("id")); | ||
| } | ||
|
|
||
| @Test | ||
| public void testQueryEdgeByPage() { | ||
| Assume.assumeTrue("Not support paging", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
neq未被规范化,可能无法利用二级索引neq(true)语义等价于eq(false),neq(false)等价于eq(true)。当前直接透传Condition.neq(key, value)到 backend,而 neq 通常走全扫描 + 过滤,无法命中 secondary index(例如strikeByArrested)。该 PR 的目标之一是让 boolean 谓词走正确的索引路径,
neq也应一并处理:这样
neq(true)→eq(false),可以命中 secondary index。