Copilot commented on code in PR #3039:
URL: https://github.com/apache/hugegraph/pull/3039#discussion_r3338752502
##########
hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CountStrategyCoreTest.java:
##########
@@ -125,4 +183,210 @@ public void
testWhereCountGteNegativeDoesNotBuildInvalidRange() {
Assert.assertEquals(4L, count);
}
+
+ @Test
+ public void testMatchWithNoIndexConditionMatchesDirectTraversal() {
+ this.initMatchNoIndexSchema();
+ this.initMatchNoIndexGraph();
+
+ long direct = graph().traversal().V()
+ .has("vp4", P.neq("J2O"))
+ .has("vl1", "vp2", P.gte(false))
+ .has("vp2")
+ .has("vl0", "vp3", P.gt(4592737712018141718L))
+ .out("el1")
+ .count().next();
+ long viaMatch = graph().traversal().V()
+ .has("vp4", P.neq("J2O"))
+ .has("vl1", "vp2", P.gte(false))
+ .match(__.<Vertex>as("start0")
+ .has("vp2")
+ .has("vl0", "vp3",
+ P.gt(4592737712018141718L))
+ .repeat(__.out("el1"))
+ .times(1)
+ .as("m0"))
+ .<Vertex>select("m0").count().next();
+
+ Assert.assertEquals(0L, direct);
+ Assert.assertEquals(direct, viaMatch);
+ }
+
+ @Test
+ public void testMatchWithIndexedRangeConditionStillExtractsHas() {
+ this.initMatchNoIndexSchema();
+ graph().schema().indexLabel("vl1ByVp2").onV("vl1")
+ .by("vp2").secondary().create();
+ this.initMatchNoIndexGraph();
+
+ GraphTraversal<Vertex, Long> traversal = graph().traversal().V()
+ .has("vp2", P.lt(true))
+
.match(__.<Vertex>as("s")
+ .has("vp2")
+ .as("m"))
+ .<Vertex>select("m")
+ .count();
+
+ HugeGraphStep<?, ?> graphStep = applyAndGetGraphStep(traversal);
+ Assert.assertEquals(1, graphStep.getHasContainers().size());
+ Assert.assertEquals("vp2",
graphStep.getHasContainers().get(0).getKey());
+ Assert.assertEquals(1L, traversal.next());
+ }
+
+ @Test
+ public void testMatchWithNoIndexConditionKeepsExtractingNextHas() {
+ this.initMatchNoIndexSchema();
+ graph().schema().indexLabel("vl1ByVp2").onV("vl1")
+ .by("vp2").secondary().create();
+ this.initMatchNoIndexGraph();
+
+ GraphTraversal<Vertex, Long> traversal = graph().traversal().V()
+ .has("vp4",
P.neq("J2O"))
+ .has("vp2", true)
+
.match(__.<Vertex>as("s")
+ .has("vp2")
+ .as("m"))
+ .<Vertex>select("m")
+ .count();
+
+ HugeGraphStep<?, ?> graphStep = applyAndGetGraphStep(traversal);
+ Assert.assertEquals(1, graphStep.getHasContainers().size());
+ Assert.assertEquals("vp2",
graphStep.getHasContainers().get(0).getKey());
+ Assert.assertTrue(hasRemainingHasStep(traversal, "vp4"));
+ Assert.assertFalse(hasRemainingHasStep(traversal, "vp2"));
+ Assert.assertEquals(1L, traversal.next());
+ }
+
+ @Test
+ public void testMatchWithIdentityKeepsNoIndexConditionLocal() {
+ this.initMatchNoIndexSchema();
+ this.initMatchNoIndexGraph();
+
+ GraphTraversal<Vertex, Long> traversal = graph().traversal().V()
+ .has("vp4",
P.neq("J2O"))
+ .identity()
+
.match(__.<Vertex>as("s")
+ .has("vp2")
+ .as("m"))
+ .<Vertex>select("m")
+ .count();
+
+ HugeGraphStep<?, ?> graphStep = applyAndGetGraphStep(traversal);
+ Assert.assertEquals(0, graphStep.getHasContainers().size());
+ Assert.assertTrue(hasRemainingHasStep(traversal, "vp4"));
+ Assert.assertEquals(1L, traversal.next());
+ }
+
+ @Test
+ public void testMatchWithIndexedEdgeRangeConditionStillExtractsHas() {
+ this.initMatchNoIndexSchema();
+ graph().schema().indexLabel("el1ByEp2").onE("el1")
+ .by("ep2").secondary().create();
+ this.initMatchNoIndexGraph();
+
+ GraphTraversal<Edge, Long> traversal = graph().traversal().E()
+ .has("ep2", P.lt(true))
+ .match(__.<Edge>as("s")
+ .has("ep2")
+ .as("m"))
+ .<Edge>select("m")
+ .count();
+
+ HugeGraphStep<?, ?> graphStep = applyAndGetGraphStep(traversal);
+ Assert.assertEquals(1, graphStep.getHasContainers().size());
+ Assert.assertEquals("ep2",
graphStep.getHasContainers().get(0).getKey());
+ Assert.assertEquals(1L, traversal.next());
+ }
+
+ @Test
+ public void testMatchWithIndexedNumericRangeConditionStillExtractsHas() {
+ this.initMatchNoIndexSchema();
+ graph().schema().indexLabel("vl0ByVp3").onV("vl0")
+ .by("vp3").range().create();
+ this.initMatchNoIndexGraph();
+
+ GraphTraversal<Vertex, Long> traversal = graph().traversal().V()
+ .has("vp3",
+
P.gt(4592737712018141718L))
+
.match(__.<Vertex>as("s")
+ .has("vp3")
+ .as("m"))
+ .<Vertex>select("m")
+ .count();
+
+ HugeGraphStep<?, ?> graphStep = applyAndGetGraphStep(traversal);
+ Assert.assertEquals(1, graphStep.getHasContainers().size());
+ Assert.assertEquals("vp3",
graphStep.getHasContainers().get(0).getKey());
+ Assert.assertFalse(hasRemainingHasStep(traversal, "vp3"));
+ Assert.assertEquals(1L, traversal.next());
+ }
+
+ @Test
+ public void testMatchWithIndexedNumericNeqConditionKeepsHas() {
+ this.initMatchNoIndexSchema();
+ graph().schema().indexLabel("vl0ByVp3").onV("vl0")
+ .by("vp3").range().create();
+ graph().schema().indexLabel("vl1ByVp2").onV("vl1")
+ .by("vp2").secondary().create();
+ this.initMatchNoIndexGraph();
+
+ GraphTraversal<Vertex, Long> traversal = graph().traversal().V()
+ .has("vp3",
+
P.neq(4592737712018141719L))
+ .has("vp2", true)
+
.match(__.<Vertex>as("s")
+ .has("vp2")
+ .as("m"))
+ .<Vertex>select("m")
+ .count();
+
+ HugeGraphStep<?, ?> graphStep = applyAndGetGraphStep(traversal);
+ Assert.assertEquals(1, graphStep.getHasContainers().size());
+ Assert.assertEquals("vp2",
graphStep.getHasContainers().get(0).getKey());
+ Assert.assertTrue(hasRemainingHasStep(traversal, "vp3"));
+ Assert.assertEquals(0L, traversal.next());
+ }
+
+ @Test
+ public void testMatchWithSystemRangeConditionMatchesDirectTraversal() {
+ this.initMatchNoIndexSchema();
+ this.initMatchNoIndexGraph();
+
+ long direct = graph().traversal().V()
+ .hasLabel("vl1")
+ .has("vp2")
+ .count().next();
+ GraphTraversal<Vertex, Long> traversal = graph().traversal().V()
+ .hasLabel(P.neq("vl0"))
+
.match(__.<Vertex>as("s")
+ .has("vp2")
+ .as("m"))
+ .<Vertex>select("m")
+ .count();
+
+ HugeGraphStep<?, ?> graphStep = applyAndGetGraphStep(traversal);
+ Assert.assertTrue(hasRemainingHasStep(traversal,
T.label.getAccessor()));
Review Comment:
The local variable `graphStep` is assigned but never used. If the intent is
only to apply strategies before inspecting the remaining `HasStep`s, call
`applyAndGetGraphStep(traversal);` without assigning it, or add assertions that
use `graphStep`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]