Skip to content

Commit e6ff06e

Browse files
committed
fix(server): avoid extracting text range filters
1 parent 454dd3d commit e6ff06e

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ public static void extractHasContainer(HugeGraphStep<?, ?> newStep,
171171
step = step.getNextStep();
172172
if (step instanceof HasStep) {
173173
HasContainerHolder holder = (HasContainerHolder) step;
174+
if (!canExtractHasContainers(TraversalUtil.getGraph(newStep),
175+
holder.getHasContainers())) {
176+
break;
177+
}
174178
for (HasContainer has : holder.getHasContainers()) {
175179
if (!GraphStep.processHasContainerIds(newStep, has)) {
176180
newStep.addHasContainer(has);
@@ -188,6 +192,10 @@ public static void extractHasContainer(HugeVertexStep<?> newStep,
188192
do {
189193
if (step instanceof HasStep) {
190194
HasContainerHolder holder = (HasContainerHolder) step;
195+
if (!canExtractHasContainers(TraversalUtil.getGraph(newStep),
196+
holder.getHasContainers())) {
197+
break;
198+
}
191199
for (HasContainer has : holder.getHasContainers()) {
192200
newStep.addHasContainer(has);
193201
}
@@ -198,6 +206,39 @@ public static void extractHasContainer(HugeVertexStep<?> newStep,
198206
} while (step instanceof HasStep || step instanceof NoOpBarrierStep);
199207
}
200208

209+
private static boolean canExtractHasContainers(HugeGraph graph,
210+
List<HasContainer> hasContainers) {
211+
for (HasContainer has : hasContainers) {
212+
if (!canExtractHasContainer(graph, has)) {
213+
return false;
214+
}
215+
}
216+
return true;
217+
}
218+
219+
private static boolean canExtractHasContainer(HugeGraph graph,
220+
HasContainer has) {
221+
if (isSysProp(has.getKey())) {
222+
return true;
223+
}
224+
225+
PropertyKey pkey = graph.propertyKey(has.getKey());
226+
if (!pkey.dataType().isText()) {
227+
return true;
228+
}
229+
230+
List<P<Object>> predicates = new ArrayList<>();
231+
collectPredicates(predicates, ImmutableList.of(has.getPredicate()));
232+
for (P<Object> pred : predicates) {
233+
BiPredicate<?, ?> bp = pred.getBiPredicate();
234+
if (bp == Compare.gt || bp == Compare.gte ||
235+
bp == Compare.lt || bp == Compare.lte) {
236+
return false;
237+
}
238+
}
239+
return true;
240+
}
241+
201242
public static void extractOrder(Step<?, ?> newStep,
202243
Traversal.Admin<?, ?> traversal) {
203244
Step<?, ?> step = newStep;

hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/core/CountStrategyCoreTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,29 @@ public void testWhereCountGteNegativeDoesNotBuildInvalidRange() {
125125

126126
Assert.assertEquals(4L, count);
127127
}
128+
129+
@Test
130+
public void testRepeatAfterTextRangeFilterWithEmptyResult() {
131+
SchemaManager schema = graph().schema();
132+
schema.propertyKey("vp4").asText().create();
133+
schema.vertexLabel("vl1").properties("vp4")
134+
.nullableKeys("vp4").create();
135+
schema.edgeLabel("el2").link("vl1", "vl1").create();
136+
137+
Vertex v1 = graph().addVertex(T.label, "vl1", "vp4", "a");
138+
Vertex v2 = graph().addVertex(T.label, "vl1", "vp4", "b");
139+
v1.addEdge("el2", v2);
140+
commitTx();
141+
142+
long direct = graph().traversal().V().has("vp4", P.lt(""))
143+
.repeat(__.out("el2")).emit().times(1)
144+
.count().next();
145+
long viaMatch = graph().traversal().V()
146+
.match(__.as("start").has("vp4", P.lt(""))
147+
.out("el2").as("m"))
148+
.select("m").count().next();
149+
150+
Assert.assertEquals(0L, direct);
151+
Assert.assertEquals(viaMatch, direct);
152+
}
128153
}

0 commit comments

Comments
 (0)