Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ private boolean doStrategy(final Step step) {
return false;
}

final P<?> predicate = ((IsStep<?>) step.getNextStep()).getPredicate();
if (predicate instanceof ConnectiveP) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

⚠️ Important: preserve safe range limiting for flat connective predicates

Returning here for every ConnectiveP bypasses the entire strategy, including the safe RangeGlobalStep insertion. Common predicates such as between(1, 18) are connective predicates, so a high-degree count().is(...) traversal now counts the complete input instead of stopping at the upper threshold. The new result assertions do not detect this plan regression. Please keep disabling the destructive NotStep/dismissCountIs rewrites unless full-expression equivalence is proven, while retaining a proven-safe range cap for analyzable flat connectives (and continue skipping nested cases as needed). Add a traversal-plan regression that asserts a representative flat connective still receives the range bound.

return false;
}

final Step parent = step.getTraversal().getParent().asStep();
return (parent instanceof FilterStep || parent.getLabels().isEmpty()) &&
!(parent.getNextStep() instanceof MatchStep.MatchEndStep &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,100 @@ public void testWhereCountGteNegativeDoesNotBuildInvalidRange() {
Assert.assertEquals(4L, count);
}

@Test
public void testWhereCountNestedConnectivePredicate() {
this.initSchema();
Vertex source = graph().addVertex(T.label, "person", "name", "source");
Vertex target = graph().addVertex(T.label, "person", "name", "target");
source.addEdge("knows", target);
commitTx();

long count = graph().traversal().V(source.id())
.where(__.both("knows").count()
.is(P.<Long>outside(1L, 18L)
.and(P.gte(0L))))
.count().next();

Assert.assertEquals(0L, count);
}

@Test
public void testWhereCountNegatedNestedConnectivePredicate() {
this.initSchema();
Vertex source = graph().addVertex(T.label, "person", "name", "source");
Vertex target = graph().addVertex(T.label, "person", "name", "target");
source.addEdge("knows", target);
commitTx();

long count = graph().traversal().V(source.id())
.where(__.both("knows").count()
.is(P.not(P.<Long>outside(1L, 18L)
.and(P.gte(0L)))))
.count().next();

Assert.assertEquals(1L, count);
}

@Test
public void testWhereCountFlatAndContradictionEmpty() {
this.initSchema();
Vertex source = graph().addVertex(T.label, "person", "name", "source");
commitTx();

long count = graph().traversal().V(source.id())
.where(__.both("knows").count()
.is(P.<Long>eq(0L).and(P.neq(0L))))
.count().next();

Assert.assertEquals(0L, count);
}

@Test
public void testWhereCountFlatAndContradictionNonEmpty() {
this.initSchema();
Vertex source = graph().addVertex(T.label, "person", "name", "source");
Vertex target = graph().addVertex(T.label, "person", "name", "target");
source.addEdge("knows", target);
commitTx();

long count = graph().traversal().V(source.id())
.where(__.both("knows").count()
.is(P.<Long>eq(0L).and(P.neq(0L))))
.count().next();

Assert.assertEquals(0L, count);
}

@Test
public void testWhereCountFlatOrTautologyEmpty() {
this.initSchema();
Vertex source = graph().addVertex(T.label, "person", "name", "source");
commitTx();

long count = graph().traversal().V(source.id())
.where(__.both("knows").count()
.is(P.<Long>eq(0L).or(P.neq(0L))))
.count().next();

Assert.assertEquals(1L, count);
}

@Test
public void testWhereCountFlatOrTautologyNonEmpty() {
this.initSchema();
Vertex source = graph().addVertex(T.label, "person", "name", "source");
Vertex target = graph().addVertex(T.label, "person", "name", "target");
source.addEdge("knows", target);
commitTx();

long count = graph().traversal().V(source.id())
.where(__.both("knows").count()
.is(P.<Long>eq(0L).or(P.neq(0L))))
.count().next();

Assert.assertEquals(1L, count);
}

@Test
public void testRepeatAfterTextRangeFilterWithEmptyResult() {
this.initTextRangeSchema(true);
Expand Down
Loading