Search in sources :

Example 21 with Query

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

the class RamTable method loadFromDB.

private void loadFromDB() throws Exception {
    Query query = new Query(HugeType.VERTEX);
    query.capacity(this.verticesCapacityHalf * 2L);
    query.limit(Query.NO_LIMIT);
    Iterator<Vertex> vertices = this.graph.vertices(query);
    // switch concurrent loading here
    boolean concurrent = true;
    if (concurrent) {
        try (LoadTraverser traverser = new LoadTraverser()) {
            traverser.load(vertices);
        }
        return;
    }
    Iterator<Edge> adjEdges;
    Id lastId = IdGenerator.ZERO;
    while (vertices.hasNext()) {
        Id vertex = (Id) vertices.next().id();
        LOG.info("scan from hbase {} loadfromDB", vertex);
        if (vertex.compareTo(lastId) < 0) {
            throw new HugeException("The ramtable feature is not " + "supported by %s backend", this.graph.backend());
        }
        ensureNumberId(vertex);
        lastId = vertex;
        adjEdges = this.graph.adjacentEdges(vertex);
        if (adjEdges.hasNext()) {
            HugeEdge edge = (HugeEdge) adjEdges.next();
            this.addEdge(true, edge);
        }
        while (adjEdges.hasNext()) {
            HugeEdge edge = (HugeEdge) adjEdges.next();
            this.addEdge(false, edge);
        }
    }
}
Also used : HugeVertex(com.baidu.hugegraph.structure.HugeVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Query(com.baidu.hugegraph.backend.query.Query) 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) Edge(org.apache.tinkerpop.gremlin.structure.Edge) HugeException(com.baidu.hugegraph.HugeException)

Example 22 with Query

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

the class SchemaTransaction method getAllSchema.

protected <T extends SchemaElement> List<T> getAllSchema(HugeType type) {
    List<T> results = new ArrayList<>();
    Query query = new Query(type);
    Iterator<BackendEntry> entries = this.query(query).iterator();
    try {
        while (entries.hasNext()) {
            BackendEntry entry = entries.next();
            if (entry == null) {
                continue;
            }
            results.add(this.deserialize(entry, type));
            Query.checkForceCapacity(results.size());
        }
    } finally {
        CloseableIterator.closeIterator(entries);
    }
    return results;
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) ArrayList(java.util.ArrayList)

Example 23 with Query

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

the class HugeTraverser method edgesOfVertex.

@Watched
protected Iterator<Edge> edgesOfVertex(Id source, Directions dir, Id label, long limit) {
    Id[] labels = {};
    if (label != null) {
        labels = new Id[] { label };
    }
    Query query = GraphTransaction.constructEdgesQuery(source, dir, labels);
    if (limit != NO_LIMIT) {
        query.limit(limit);
    }
    return this.graph.edges(query);
}
Also used : Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 24 with Query

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

the class HugeTraverser method edgesCount.

protected long edgesCount(Id source, EdgeStep edgeStep) {
    Id[] edgeLabels = edgeStep.edgeLabels();
    Query query = GraphTransaction.constructEdgesQuery(source, edgeStep.direction(), edgeLabels);
    this.fillFilterBySortKeys(query, edgeLabels, edgeStep.properties());
    query.aggregate(Aggregate.AggregateFunc.COUNT, null);
    query.capacity(Query.NO_CAPACITY);
    query.limit(Query.NO_LIMIT);
    long count = graph().queryNumber(query).longValue();
    if (edgeStep.degree() == NO_LIMIT || count < edgeStep.degree()) {
        return count;
    } else if (edgeStep.skipDegree() != 0L && count >= edgeStep.skipDegree()) {
        return 0L;
    } else {
        return edgeStep.degree();
    }
}
Also used : Query(com.baidu.hugegraph.backend.query.Query) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Id(com.baidu.hugegraph.backend.id.Id)

Example 25 with Query

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

the class HugeGraphStep method edges.

private Iterator<E> edges() {
    LOG.debug("HugeGraphStep.edges(): {}", this);
    HugeGraph graph = TraversalUtil.getGraph(this);
    // g.E().hasId(EMPTY_LIST) will set ids to null
    if (this.ids == null) {
        return QueryResults.emptyIterator();
    }
    if (this.hasIds()) {
        return TraversalUtil.filterResult(this.hasContainers, graph.edges(this.ids));
    }
    Query query = this.makeQuery(graph, HugeType.EDGE);
    @SuppressWarnings("unchecked") Iterator<E> result = (Iterator<E>) graph.edges(query);
    return result;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) Query(com.baidu.hugegraph.backend.query.Query) Iterator(java.util.Iterator)

Aggregations

Query (com.baidu.hugegraph.backend.query.Query)31 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)24 Id (com.baidu.hugegraph.backend.id.Id)11 HugeGraph (com.baidu.hugegraph.HugeGraph)9 IdQuery (com.baidu.hugegraph.backend.query.IdQuery)9 HugeType (com.baidu.hugegraph.type.HugeType)7 Iterator (java.util.Iterator)7 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)6 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)6 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)6 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)6 BackendEntry (com.baidu.hugegraph.backend.store.BackendEntry)5 Edge (org.apache.tinkerpop.gremlin.structure.Edge)5 Test (org.junit.Test)5 HugeException (com.baidu.hugegraph.HugeException)4 BackendException (com.baidu.hugegraph.backend.BackendException)4 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)4 ArrayList (java.util.ArrayList)4 IdPrefixQuery (com.baidu.hugegraph.backend.query.IdPrefixQuery)3 IdRangeQuery (com.baidu.hugegraph.backend.query.IdRangeQuery)3