use of org.janusgraph.core.JanusGraphMultiVertexQuery in project janusgraph by JanusGraph.
the class JanusGraphPropertiesStep method prefetchNextBatch.
/**
* This initialisation method is called when an attempt to retrieve a vertex from the cached multiQuery results
* doesn't find an entry.
*/
private void prefetchNextBatch() {
final JanusGraphMultiVertexQuery multiQuery = JanusGraphTraversalUtil.getTx(getTraversal()).multiQuery();
multiQuery.addAllVertices(verticesToPrefetch);
verticesToPrefetch.clear();
makeQuery(multiQuery);
try {
multiQueryResults = multiQuery.properties();
} catch (JanusGraphException janusGraphException) {
if (janusGraphException.isCausedBy(InterruptedException.class)) {
throw new TraversalInterruptedException();
}
}
}
use of org.janusgraph.core.JanusGraphMultiVertexQuery in project janusgraph by JanusGraph.
the class JanusGraphVertexStep method initialize.
@SuppressWarnings("deprecation")
private void initialize() {
assert !initialized;
initialized = true;
if (useMultiQuery) {
if (!starts.hasNext())
throw FastNoSuchElementException.instance();
JanusGraphMultiVertexQuery multiQuery = JanusGraphTraversalUtil.getTx(traversal).multiQuery();
List<Traverser.Admin<Vertex>> vertices = new ArrayList<>();
starts.forEachRemaining(v -> {
vertices.add(v);
multiQuery.addVertex(v.get());
});
starts.add(vertices.iterator());
assert vertices.size() > 0;
makeQuery(multiQuery);
multiQueryResults = (Vertex.class.isAssignableFrom(getReturnClass())) ? multiQuery.vertices() : multiQuery.edges();
}
}
use of org.janusgraph.core.JanusGraphMultiVertexQuery in project janusgraph by JanusGraph.
the class JanusGraphVertexStep method prefetchNextBatch.
/**
* This initialisation method is called when an attempt to retrieve a vertex from the cached multiQuery results
* doesn't find an entry.
*/
private void prefetchNextBatch(final Traverser.Admin<Vertex> traverser) {
final JanusGraphMultiVertexQuery multiQuery = JanusGraphTraversalUtil.getTx(getTraversal()).multiQuery();
if (verticesToPrefetch.isEmpty()) {
multiQuery.addVertex(JanusGraphTraversalUtil.getJanusGraphVertex(traverser));
} else {
multiQuery.addAllVertices(verticesToPrefetch);
verticesToPrefetch.clear();
}
makeQuery(multiQuery);
try {
multiQueryResults = (Vertex.class.isAssignableFrom(getReturnClass())) ? multiQuery.vertices() : multiQuery.edges();
} catch (JanusGraphException janusGraphException) {
if (janusGraphException.isCausedBy(InterruptedException.class)) {
throw new TraversalInterruptedException();
}
}
}
use of org.janusgraph.core.JanusGraphMultiVertexQuery in project janusgraph by JanusGraph.
the class JanusGraphVertexStep method flatMap.
@Override
protected Iterator<E> flatMap(final Traverser.Admin<Vertex> traverser) {
Iterable<? extends JanusGraphElement> result;
if (useMultiQuery) {
if (multiQueryResults == null || !multiQueryResults.containsKey(traverser.get())) {
// current batch is exhausted, fetch new batch
prefetchNextBatch(traverser);
}
result = multiQueryResults.get(traverser.get());
} else {
final JanusGraphVertexQuery query = makeQuery((JanusGraphTraversalUtil.getJanusGraphVertex(traverser)).query());
result = (Vertex.class.isAssignableFrom(getReturnClass())) ? query.vertices() : query.edges();
}
if (batchPropertyPrefetching && txVertexCacheSize > 1) {
Set<Vertex> vertices = new HashSet<>();
for (JanusGraphElement v : result) {
vertices.add((Vertex) v);
if (vertices.size() >= txVertexCacheSize) {
break;
}
}
// populate the vertex cache so subsequent queries of properties don't have to go to the storage back end
if (vertices.size() > 1) {
JanusGraphMultiVertexQuery propertyMultiQuery = JanusGraphTraversalUtil.getTx(traversal).multiQuery();
((BasicVertexCentricQueryBuilder) propertyMultiQuery).profiler(queryProfiler);
propertyMultiQuery.addAllVertices(vertices).preFetch();
}
}
return (Iterator<E>) result.iterator();
}
use of org.janusgraph.core.JanusGraphMultiVertexQuery in project janusgraph by JanusGraph.
the class JanusGraphEdgeVertexStep method initialize.
private void initialize() {
assert !initialized;
initialized = true;
if (!starts.hasNext()) {
throw FastNoSuchElementException.instance();
}
if (txVertexCacheSize < 2) {
return;
}
List<Traverser.Admin<Edge>> edges = new ArrayList<>();
Set<Vertex> vertices = new HashSet<>();
do {
Traverser.Admin<Edge> e = starts.next();
edges.add(e);
if (vertices.size() < txVertexCacheSize) {
if (Direction.IN.equals(direction)) {
vertices.add(e.get().inVertex());
} else if (Direction.OUT.equals(direction)) {
vertices.add(e.get().outVertex());
} else if (Direction.BOTH.equals(direction)) {
vertices.add(e.get().inVertex());
vertices.add(e.get().outVertex());
}
}
} while (starts.hasNext());
// populate the vertex cache so subsequent queries of properties don't have to go to the storage back end
if (vertices.size() > 1) {
JanusGraphMultiVertexQuery multiQuery = JanusGraphTraversalUtil.getTx(traversal).multiQuery();
((BasicVertexCentricQueryBuilder) multiQuery).profiler(queryProfiler);
multiQuery.addAllVertices(vertices).preFetch();
}
starts.add(edges.iterator());
}
Aggregations