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);
}
}
}
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;
}
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);
}
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();
}
}
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;
}
Aggregations