Skip to content

Commit dc441b6

Browse files
committed
test: cover boolean range query edge cases
1 parent 98fef9a commit dc441b6

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,26 @@ private static boolean validRange(Relation low, Relation high) {
427427
if (low == null || high == null) {
428428
return true;
429429
}
430-
return compare(low, high) < 0 || compare(low, high) == 0 &&
431-
low.relation() == Condition.RelationType.GTE &&
432-
high.relation() == Condition.RelationType.LTE;
430+
int compared = compare(low, high);
431+
if (compared > 0) {
432+
return false;
433+
}
434+
if (compared == 0) {
435+
return low.relation() == Condition.RelationType.GTE &&
436+
high.relation() == Condition.RelationType.LTE;
437+
}
438+
return !emptyBooleanRange(low, high);
439+
}
440+
441+
private static boolean emptyBooleanRange(Relation low, Relation high) {
442+
if (!(low.value() instanceof Boolean) ||
443+
!(high.value() instanceof Boolean)) {
444+
return false;
445+
}
446+
return Boolean.FALSE.equals(low.value()) &&
447+
Boolean.TRUE.equals(high.value()) &&
448+
low.relation() == Condition.RelationType.GT &&
449+
high.relation() == Condition.RelationType.LT;
433450
}
434451

435452
private static boolean validEq(Relation eq, Relation low, Relation high) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7121,6 +7121,8 @@ public void testQueryEdgeWithNullablePropertyInCompositeIndex() {
71217121
public void testQueryEdgeByBooleanRangePredicate() {
71227122
HugeGraph graph = graph();
71237123
initStrikeIndex();
7124+
graph.schema().indexLabel("strikeByArrested").onE("strike").secondary()
7125+
.by("arrested").create();
71247126

71257127
Vertex louise = graph.addVertex(T.label, "person", "name", "Louise",
71267128
"city", "Beijing", "age", 21);

0 commit comments

Comments
 (0)