Search in sources :

Example 11 with ConditionQuery

use of com.baidu.hugegraph.backend.query.ConditionQuery 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 ConditionQuery

use of com.baidu.hugegraph.backend.query.ConditionQuery 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 ConditionQuery

use of com.baidu.hugegraph.backend.query.ConditionQuery 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 ConditionQuery

use of com.baidu.hugegraph.backend.query.ConditionQuery 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 ConditionQuery

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

the class TableSerializer method writeQueryCondition.

@Override
protected Query writeQueryCondition(Query query) {
    ConditionQuery result = (ConditionQuery) query;
    // No user-prop when serialize
    assert result.allSysprop();
    for (Condition.Relation r : result.relations()) {
        if (!r.value().equals(r.serialValue())) {
            // Has been serialized before (maybe share a query multi times)
            continue;
        }
        HugeKeys key = (HugeKeys) r.key();
        if (r.relation() == Condition.RelationType.IN) {
            E.checkArgument(r.value() instanceof List, "Expect list value for IN condition: %s", r);
            List<?> values = (List<?>) r.value();
            List<Object> serializedValues = new ArrayList<>(values.size());
            for (Object v : values) {
                serializedValues.add(this.serializeValue(key, v));
            }
            r.serialValue(serializedValues);
        } else if (r.relation() == Condition.RelationType.CONTAINS_VALUE && query.resultType().isGraph()) {
            r.serialValue(this.writeProperty(null, r.value()));
        } else {
            r.serialValue(this.serializeValue(key, r.value()));
        }
    }
    return result;
}
Also used : Condition(com.baidu.hugegraph.backend.query.Condition) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HugeKeys(com.baidu.hugegraph.type.define.HugeKeys)

Aggregations

ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)59 Id (com.baidu.hugegraph.backend.id.Id)19 Test (org.junit.Test)19 Condition (com.baidu.hugegraph.backend.query.Condition)17 HugeGraph (com.baidu.hugegraph.HugeGraph)13 ArrayList (java.util.ArrayList)12 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)10 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)10 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)8 Collection (java.util.Collection)8 Query (com.baidu.hugegraph.backend.query.Query)7 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)7 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)7 Map (java.util.Map)7 Edge (org.apache.tinkerpop.gremlin.structure.Edge)7 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)6 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)5 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)5 HugeType (com.baidu.hugegraph.type.HugeType)5 ImmutableMap (com.google.common.collect.ImmutableMap)5