Search in sources :

Example 11 with Condition

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);
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 12 with Condition

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);
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 13 with Condition

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);
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 14 with Condition

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);
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) ArrayList(java.util.ArrayList) Collection(java.util.Collection) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 15 with Condition

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());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) Date(java.util.Date) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

Condition (com.baidu.hugegraph.backend.query.Condition)49 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)29 Test (org.junit.Test)29 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)16 ArrayList (java.util.ArrayList)13 Id (com.baidu.hugegraph.backend.id.Id)12 Collection (java.util.Collection)8 Date (java.util.Date)8 SyspropRelation (com.baidu.hugegraph.backend.query.Condition.SyspropRelation)6 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)4 RangeConditions (com.baidu.hugegraph.backend.query.Condition.RangeConditions)4 Relation (com.baidu.hugegraph.backend.query.Condition.Relation)4 HugeException (com.baidu.hugegraph.HugeException)3 IdPrefixQuery (com.baidu.hugegraph.backend.query.IdPrefixQuery)3 IdRangeQuery (com.baidu.hugegraph.backend.query.IdRangeQuery)3 HugeType (com.baidu.hugegraph.type.HugeType)3 Directions (com.baidu.hugegraph.type.define.Directions)3 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)3 AndP (org.apache.tinkerpop.gremlin.process.traversal.util.AndP)3 OrP (org.apache.tinkerpop.gremlin.process.traversal.util.OrP)3