Search in sources :

Example 46 with Condition

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

the class ConditionTest method testConditionIn.

@Test
public void testConditionIn() {
    Condition c1 = Condition.in(HugeKeys.ID, ImmutableList.of(1, 2, "3"));
    Assert.assertTrue(c1.test(1));
    Assert.assertTrue(c1.test(2));
    Assert.assertTrue(c1.test("3"));
    Assert.assertFalse(c1.test(4));
    Assert.assertFalse(c1.test(1.0));
    Assert.assertFalse(c1.test(2.0));
    Assert.assertFalse(c1.test(3));
    Assert.assertFalse(c1.test(123));
    Assert.assertFalse(c1.test(1.01));
    Assert.assertFalse(c1.test("123"));
    Assert.assertFalse(c1.test("123.0"));
    Assert.assertFalse(c1.test("1"));
    Assert.assertFalse(c1.test("2"));
    Assert.assertFalse(c1.test("3.0"));
    Assert.assertFalse(c1.test("1.0"));
    Assert.assertFalse(c1.test((Object) null));
    Assert.assertFalse(c1.test(ImmutableList.of(1, 2)));
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition.in(HugeKeys.ID, null).test("1");
    }, e -> {
        Assert.assertEquals("Can't test null value for `in`", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        Condition c2 = new SyspropRelation(HugeKeys.ID, RelationType.IN, "single-value");
        c2.test("singlevalue");
    }, e -> {
        Assert.assertEquals("Can't test 'single-value'(String) for `in`, " + "expect Collection", e.getMessage());
    });
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) SyspropRelation(com.baidu.hugegraph.backend.query.Condition.SyspropRelation) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 47 with Condition

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

the class ConditionQueryFlattenTest method testFlattenWithIn.

@Test
public void testFlattenWithIn() {
    Id key = IdGenerator.of("c1");
    ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
    query.query(Condition.in(key, ImmutableList.of("1", "2", "3")));
    Assert.assertEquals(1, query.conditions().size());
    List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
    Assert.assertEquals(3, queries.size());
    List<Condition> expect = ImmutableList.of(Condition.eq(key, "1"), Condition.eq(key, "2"), Condition.eq(key, "3"));
    List<Condition> actual = new ArrayList<>();
    for (ConditionQuery q : queries) {
        Assert.assertEquals(1, q.conditions().size());
        actual.add(q.conditions().iterator().next());
    }
    Assert.assertEquals(expect, actual);
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) ArrayList(java.util.ArrayList) Id(com.baidu.hugegraph.backend.id.Id) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 48 with Condition

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

the class ConditionQueryFlattenTest method testFlattenWithNotIn.

@Test
public void testFlattenWithNotIn() {
    Id key = IdGenerator.of("c1");
    ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
    query.query(Condition.nin(key, ImmutableList.of("1", "2", "3")));
    Assert.assertEquals(1, query.conditions().size());
    List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
    Assert.assertEquals(1, queries.size());
    List<Condition> expect = ImmutableList.of(Condition.neq(key, "1"), Condition.neq(key, "2"), Condition.neq(key, "3"));
    Collection<Condition> actual = queries.iterator().next().conditions();
    Assert.assertEquals(expect, actual);
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Id(com.baidu.hugegraph.backend.id.Id) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 49 with Condition

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

the class ConditionQueryFlattenTest method testFlattenWithAndTree.

@Test
public void testFlattenWithAndTree() {
    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).and(c3.and(c4)));
    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, 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)

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