Search in sources :

Example 6 with Condition

use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.

the class ConditionTest method testConditionContains.

@Test
public void testConditionContains() {
    Condition c1 = Condition.contains(HugeKeys.ID, "v1");
    Assert.assertTrue(c1.test(ImmutableList.of("v1", "v2")));
    Assert.assertTrue(c1.test(ImmutableList.of("v1", "v3")));
    Assert.assertFalse(c1.test(ImmutableList.of("v3", "v4")));
    Condition c2 = Condition.contains(HugeKeys.ID, ImmutableList.of("v1", "v2"));
    Assert.assertFalse(c2.test(ImmutableList.of("v1", "v2", "v3")));
    Assert.assertTrue(c2.test(ImmutableList.of(ImmutableList.of("v1", "v2"), "v3")));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        c1.test((Object) null);
    }, e -> {
        Assert.assertEquals("Can't execute `contains` on type null, " + "expect Collection", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        c1.test("v1");
    }, e -> {
        Assert.assertEquals("Can't execute `contains` on type String, " + "expect Collection", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        c1.test(123);
    }, e -> {
        Assert.assertEquals("Can't execute `contains` on type Integer, " + "expect Collection", e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 7 with Condition

use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.

the class ConditionTest method testConditionScan.

@Test
public void testConditionScan() {
    Condition c1 = Condition.scan("abc", "axy");
    Assert.assertTrue(c1.test("abc"));
    Assert.assertTrue(c1.test("abd"));
    Assert.assertTrue(c1.test("abz"));
    Assert.assertTrue(c1.test("axx"));
    // test of scan will return true for any case
    Assert.assertTrue(c1.test("abb"));
    Assert.assertTrue(c1.test("axy"));
    Assert.assertTrue(c1.test("axz"));
    Assert.assertTrue(c1.test((Object) null));
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 8 with Condition

use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.

the class ConditionQueryFlattenTest method testFlattenWithOrAndTree.

@Test
public void testFlattenWithOrAndTree() {
    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.and(c2).or(c3.and(c4)));
    Assert.assertEquals(1, query.conditions().size());
    List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
    Assert.assertEquals(2, queries.size());
    List<Collection<Condition>> expect;
    expect = ImmutableList.of(ImmutableList.of(c1, c2), ImmutableList.of(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 9 with Condition

use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.

the class ConditionQueryFlattenTest method testFlattenWithOr.

@Test
public void testFlattenWithOr() {
    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.or(c2));
    Assert.assertEquals(1, query.conditions().size());
    List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
    Assert.assertEquals(2, queries.size());
    List<Collection<Condition>> expect;
    expect = ImmutableList.of(ImmutableList.of(c1), ImmutableList.of(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 10 with Condition

use of com.baidu.hugegraph.backend.query.Condition in project incubator-hugegraph by apache.

the class ConditionQueryFlattenTest method testFlattenWithOrTree.

@Test
public void testFlattenWithOrTree() {
    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).or(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), ImmutableList.of(c2), ImmutableList.of(c3), ImmutableList.of(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)

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