Search in sources :

Example 56 with ConditionQuery

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

the class VertexCoreTest method testScanVertexInPaging.

@Test
public void testScanVertexInPaging() {
    HugeGraph graph = graph();
    Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange());
    this.init10VerticesAndCommit();
    List<Vertex> vertices = new LinkedList<>();
    ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
    String backend = graph.backend();
    if (backend.equals("cassandra") || backend.equals("scylladb")) {
        query.scan(String.valueOf(Long.MIN_VALUE), String.valueOf(Long.MAX_VALUE));
    } else {
        query.scan(BackendTable.ShardSplitter.START, BackendTable.ShardSplitter.END);
    }
    query.limit(1);
    String page = PageInfo.PAGE_NONE;
    while (page != null) {
        query.page(page);
        Iterator<Vertex> iterator = graph.vertices(query);
        while (iterator.hasNext()) {
            Vertex vertex = iterator.next();
            Assert.assertTrue(query.test((HugeElement) vertex));
            vertices.add(vertex);
        }
        page = PageInfo.pageInfo(iterator);
        CloseableIterator.closeIterator(iterator);
    }
    Assert.assertEquals(10, vertices.size());
}
Also used : FakeVertex(com.baidu.hugegraph.testutil.FakeObjects.FakeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) LinkedList(java.util.LinkedList) HugeElement(com.baidu.hugegraph.structure.HugeElement) Test(org.junit.Test)

Example 57 with ConditionQuery

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

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

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

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