Search in sources :

Example 51 with ConditionQuery

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

the class EdgeCoreTest method testScanEdgeInPaging.

@Test
public void testScanEdgeInPaging() {
    HugeGraph graph = graph();
    Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange());
    init18Edges();
    List<Edge> edges = new LinkedList<>();
    ConditionQuery query = new ConditionQuery(HugeType.EDGE);
    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<Edge> iterator = graph.edges(query);
        while (iterator.hasNext()) {
            edges.add(iterator.next());
        }
        page = PageInfo.pageInfo(iterator);
        CloseableIterator.closeIterator(iterator);
    }
    Assert.assertEquals(18, edges.size());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) FakeEdge(com.baidu.hugegraph.testutil.FakeObjects.FakeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 52 with ConditionQuery

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

the class EdgeCoreTest method testQueryEdgesByInvalidSysprop.

@Test
public void testQueryEdgesByInvalidSysprop() {
    HugeGraph graph = graph();
    init18Edges();
    List<Edge> edges = graph.traversal().E().hasLabel("know").toList();
    Assert.assertEquals(1, edges.size());
    HugeEdge edge = (HugeEdge) edges.get(0);
    Id id = edge.id();
    Id know = edge.schemaLabel().id();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.traversal().E().hasLabel("know").has("ID", id).toList();
    }, e -> {
        Assert.assertContains("Undefined property key: 'ID'", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.traversal().E().hasLabel("know").has("NAME", "n1").toList();
    }, e -> {
        Assert.assertContains("Undefined property key: 'NAME'", e.getMessage());
    });
    Assert.assertThrows(HugeException.class, () -> {
        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
        query.eq(HugeKeys.LABEL, know);
        query.query(id);
        graph.edges(query).hasNext();
    }, e -> {
        Assert.assertContains("Not supported querying by id and conditions", e.getMessage());
    });
    Assert.assertThrows(HugeException.class, () -> {
        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
        query.eq(HugeKeys.LABEL, know);
        query.eq(HugeKeys.NAME, "n1");
        graph.edges(query).hasNext();
    }, e -> {
        Assert.assertContains("Not supported querying edges by", e.getMessage());
        Assert.assertContains("NAME == n1", e.getMessage());
    });
    Assert.assertThrows(HugeException.class, () -> {
        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
        query.eq(HugeKeys.LABEL, know);
        query.eq(HugeKeys.NAME, "n2");
        query.query(Condition.eq(IdGenerator.of("fake"), "n3"));
        graph.edges(query).hasNext();
    }, e -> {
        Assert.assertContains("Can't do index query with [", e.getMessage());
        Assert.assertContains("LABEL == ", e.getMessage());
        Assert.assertContains("NAME == n2", e.getMessage());
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) Id(com.baidu.hugegraph.backend.id.Id) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) FakeEdge(com.baidu.hugegraph.testutil.FakeObjects.FakeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Test(org.junit.Test)

Example 53 with ConditionQuery

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

the class EdgeCoreTest method testScanEdge.

@Test
public void testScanEdge() {
    HugeGraph graph = graph();
    Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange());
    init18Edges();
    Set<Edge> edges = new HashSet<>();
    long splitSize = 1L * 1024L * 1024L;
    List<Shard> splits = graph.metadata(HugeType.EDGE_OUT, "splits", splitSize);
    for (Shard split : splits) {
        ConditionQuery q = new ConditionQuery(HugeType.EDGE);
        q.scan(split.start(), split.end());
        edges.addAll(ImmutableList.copyOf(graph.edges(q)));
    }
    Assert.assertEquals(18, edges.size());
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Shard(com.baidu.hugegraph.backend.store.Shard) HugeEdge(com.baidu.hugegraph.structure.HugeEdge) FakeEdge(com.baidu.hugegraph.testutil.FakeObjects.FakeEdge) Edge(org.apache.tinkerpop.gremlin.structure.Edge) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 54 with ConditionQuery

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

the class EdgeCoreTest method testQueryEdgesByDirection.

@Test
public void testQueryEdgesByDirection() {
    HugeGraph graph = graph();
    init18Edges();
    // Query vertex by condition (filter by Direction)
    ConditionQuery q = new ConditionQuery(HugeType.EDGE);
    q.eq(HugeKeys.DIRECTION, Direction.OUT);
    Assert.assertThrows(HugeException.class, () -> {
        graph.edges(q);
    });
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Test(org.junit.Test)

Example 55 with ConditionQuery

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

the class VertexCoreTest method testQueryByInvalidSysprop.

@Test
public void testQueryByInvalidSysprop() {
    HugeGraph graph = graph();
    init10Vertices();
    List<Vertex> vertices = graph.traversal().V().hasLabel("author").has("id", 1).toList();
    Assert.assertEquals(1, vertices.size());
    Vertex vertex = vertices.get(0);
    Id author = graph.vertexLabel(vertex.label()).id();
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.traversal().V().hasLabel("author").has("ID", 1).toList();
    }, e -> {
        Assert.assertContains("Undefined property key: 'ID'", e.getMessage());
    });
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        graph.traversal().V().hasLabel("author").has("NAME", "n1").toList();
    }, e -> {
        Assert.assertContains("Undefined property key: 'NAME'", e.getMessage());
    });
    Assert.assertThrows(HugeException.class, () -> {
        ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
        query.eq(HugeKeys.LABEL, author);
        query.query((Id) vertex.id());
        graph.vertices(query).hasNext();
    }, e -> {
        Assert.assertContains("Not supported querying by id and conditions", e.getMessage());
    });
    Assert.assertThrows(HugeException.class, () -> {
        ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
        query.eq(HugeKeys.LABEL, author);
        query.eq(HugeKeys.NAME, "n1");
        graph.vertices(query).hasNext();
    }, e -> {
        Assert.assertContains("Not supported querying vertices by", e.getMessage());
        Assert.assertContains("NAME == n1", e.getMessage());
    });
    Assert.assertThrows(HugeException.class, () -> {
        ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
        query.eq(HugeKeys.LABEL, author);
        query.eq(HugeKeys.NAME, "n2");
        query.query(Condition.eq(IdGenerator.of("fake"), "n3"));
        graph.vertices(query).hasNext();
    }, e -> {
        Assert.assertContains("Can't do index query with [", e.getMessage());
        Assert.assertContains("LABEL == ", e.getMessage());
        Assert.assertContains("NAME == n2", e.getMessage());
    });
}
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) Id(com.baidu.hugegraph.backend.id.Id) 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