use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionQueryFlattenTest method testFlattenWithMultiOr.
@Test
public void testFlattenWithMultiOr() {
Condition c1 = Condition.eq(IdGenerator.of("c1"), "1");
Condition c2 = Condition.eq(IdGenerator.of("c2"), "2");
Condition c3 = Condition.eq(IdGenerator.of("c3"), "3");
Condition c4 = Condition.eq(IdGenerator.of("c4"), "4");
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.query(c1.or(c2));
query.query(c3.or(c4));
Assert.assertEquals(2, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(4, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1, c3), ImmutableList.of(c1, c4), ImmutableList.of(c2, c3), ImmutableList.of(c2, c4));
List<Collection<Condition>> actual = new ArrayList<>();
for (ConditionQuery q : queries) {
actual.add(q.conditions());
}
Assert.assertEquals(expect, actual);
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionQueryFlattenTest method testFlattenWithAnd.
@Test
public void testFlattenWithAnd() {
Condition c1 = Condition.eq(IdGenerator.of("c1"), "1");
Condition c2 = Condition.eq(IdGenerator.of("c2"), "2");
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.query(c1.and(c2));
Assert.assertEquals(1, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(1, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1, c2));
List<Collection<Condition>> actual = new ArrayList<>();
for (ConditionQuery q : queries) {
actual.add(q.conditions());
}
Assert.assertEquals(expect, actual);
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionQueryFlattenTest method testFlattenWithAndOrTree.
@Test
public void testFlattenWithAndOrTree() {
Condition c1 = Condition.eq(IdGenerator.of("c1"), "1");
Condition c2 = Condition.eq(IdGenerator.of("c2"), "2");
Condition c3 = Condition.eq(IdGenerator.of("c3"), "3");
Condition c4 = Condition.eq(IdGenerator.of("c4"), "4");
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.query(c1.or(c2).and(c3.or(c4)));
Assert.assertEquals(1, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(4, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1, c3), ImmutableList.of(c1, c4), ImmutableList.of(c2, c3), ImmutableList.of(c2, c4));
List<Collection<Condition>> actual = new ArrayList<>();
for (ConditionQuery q : queries) {
actual.add(q.conditions());
}
Assert.assertEquals(expect, actual);
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionQueryFlattenTest method testFlattenWithMultiAnd.
@Test
public void testFlattenWithMultiAnd() {
Condition c1 = Condition.eq(IdGenerator.of("c1"), "1");
Condition c2 = Condition.eq(IdGenerator.of("c2"), "2");
Condition c3 = Condition.eq(IdGenerator.of("c3"), "3");
Condition c4 = Condition.eq(IdGenerator.of("c4"), "4");
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.query(c1);
query.query(c2);
query.query(c3);
query.query(c4);
Assert.assertEquals(4, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(1, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1, c2, c3, c4));
List<Collection<Condition>> actual = new ArrayList<>();
for (ConditionQuery q : queries) {
actual.add(q.conditions());
}
Assert.assertEquals(expect, actual);
}
use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.
the class ConditionTest method testConditionNeq.
@Test
public void testConditionNeq() {
Condition c1 = Condition.neq(HugeKeys.ID, 123);
Assert.assertTrue(c1.test(124));
Assert.assertTrue(c1.test(122.9));
Assert.assertTrue(c1.test(20));
Assert.assertFalse(c1.test(123));
Assert.assertFalse(c1.test(123.0));
Assert.assertFalse(c1.test("123"));
Assert.assertFalse(c1.test("123.0"));
Assert.assertTrue(c1.test("123.01"));
Assert.assertTrue(c1.test("20"));
// null means 0
Assert.assertTrue(c1.test((Object) null));
Condition c2 = Condition.neq(HugeKeys.ID, 0);
Assert.assertFalse(c2.test((Object) null));
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.neq(HugeKeys.ID, "123").test(123);
}, e -> {
String err = "Can't compare between 123(Integer) and 123(String)";
Assert.assertEquals(err, e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
Condition.neq(HugeKeys.ID, "123").test(new Date(0L));
}, e -> {
String err = String.format("Can't compare between %s(Date) " + "and 123(String)", new Date(0L));
Assert.assertEquals(err, e.getMessage());
});
}
Aggregations