use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class ConditionQueryFlatten method calcValidRange.
private static Relations calcValidRange(Relation gte, Relation gt, Relation eq, Relation lte, Relation lt) {
Relations result = new Relations();
Relation lower = null;
Relation upper = null;
if (gte != null) {
lower = gte;
}
if (gt != null) {
// Select bigger one in (gt, gte) as lower limit
lower = highRelation(gte, gt);
}
if (lt != null) {
upper = lt;
}
if (lte != null) {
// Select smaller one in (lt, lte) as upper limit
upper = lowRelation(lte, lt);
}
// Ensure low < high
if (!validRange(lower, upper)) {
return Relations.of();
}
// Handle eq
if (eq != null) {
if (!validEq(eq, lower, upper)) {
return Relations.of();
}
result.add(eq);
return result;
}
// No eq if come here
assert lower != null || upper != null;
if (lower != null) {
result.add(lower);
}
if (upper != null) {
result.add(upper);
}
return result;
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class ConditionTest method testConditionEqWithSysprop.
@Test
public void testConditionEqWithSysprop() {
Condition c1 = Condition.eq(HugeKeys.ID, "123");
Assert.assertEquals("ID == 123", c1.toString());
Assert.assertTrue(c1.isRelation());
Assert.assertTrue(c1.isSysprop());
Assert.assertTrue(c1.isFlattened());
Assert.assertFalse(c1.isLogic());
Assert.assertTrue(c1.test("123"));
Assert.assertFalse(c1.test("1234"));
Assert.assertFalse(c1.test(123));
Assert.assertFalse(c1.test(new Date(123)));
Assert.assertFalse(c1.test((Object) null));
Relation r1 = (Relation) c1;
Assert.assertEquals(HugeKeys.ID, r1.key());
Assert.assertEquals("123", r1.value());
Assert.assertEquals("123", r1.serialValue());
Assert.assertEquals(RelationType.EQ, r1.relation());
Assert.assertTrue(r1.test("123"));
Relation r2 = (Relation) c1.copy();
Assert.assertEquals(r1, r2);
Assert.assertEquals(HugeKeys.ID, r2.key());
Assert.assertEquals("123", r2.value());
Assert.assertEquals("123", r2.serialValue());
Assert.assertEquals(RelationType.EQ, r2.relation());
Assert.assertTrue(r2.test("123"));
r2.serialValue("1234");
Assert.assertEquals("1234", r2.serialValue());
Assert.assertEquals("123", r1.serialValue());
Assert.assertTrue(r2.test("123"));
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.eq(HugeKeys.ID, null).test("any");
}, e -> {
Assert.assertEquals("Can't test null value for `==`", e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.Condition.Relation in project incubator-hugegraph by apache.
the class ConditionTest method testConditionEqWithUserprop.
@Test
public void testConditionEqWithUserprop() {
Condition c1 = Condition.eq(IdGenerator.of("1"), "123");
Assert.assertEquals("1 == 123", c1.toString());
Assert.assertTrue(c1.isRelation());
Assert.assertFalse(c1.isSysprop());
Assert.assertTrue(c1.isFlattened());
Assert.assertFalse(c1.isLogic());
Assert.assertTrue(c1.test("123"));
Assert.assertFalse(c1.test("1234"));
Assert.assertFalse(c1.test(123));
Assert.assertFalse(c1.test(new Date(123)));
Assert.assertFalse(c1.test((Object) null));
Relation r1 = (Relation) c1;
Assert.assertEquals(IdGenerator.of("1"), r1.key());
Assert.assertEquals("123", r1.value());
Assert.assertEquals("123", r1.serialValue());
Assert.assertEquals(RelationType.EQ, r1.relation());
Assert.assertTrue(r1.test("123"));
Relation r2 = (Relation) c1.copy();
Assert.assertEquals(r1, r2);
Assert.assertEquals(IdGenerator.of("1"), r2.key());
Assert.assertEquals("123", r2.value());
Assert.assertEquals("123", r2.serialValue());
Assert.assertEquals(RelationType.EQ, r2.relation());
Assert.assertTrue(r2.test("123"));
r2.serialValue("1234");
Assert.assertEquals("1234", r2.serialValue());
Assert.assertEquals("123", r1.serialValue());
Assert.assertTrue(r2.test("123"));
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.eq(IdGenerator.of("1"), null).test("any");
}, e -> {
Assert.assertEquals("Can't test null value for `==`", e.getMessage());
});
}
Aggregations