Search in sources :

Example 1 with JanusGraphMultiVertexQuery

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();
        }
    }
}
Also used : JanusGraphMultiVertexQuery(org.janusgraph.core.JanusGraphMultiVertexQuery) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException) JanusGraphException(org.janusgraph.core.JanusGraphException) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException)

Example 2 with JanusGraphMultiVertexQuery

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();
    }
}
Also used : JanusGraphMultiVertexQuery(org.janusgraph.core.JanusGraphMultiVertexQuery) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ArrayList(java.util.ArrayList)

Example 3 with JanusGraphMultiVertexQuery

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();
        }
    }
}
Also used : JanusGraphMultiVertexQuery(org.janusgraph.core.JanusGraphMultiVertexQuery) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphException(org.janusgraph.core.JanusGraphException) TraversalInterruptedException(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException)

Example 4 with JanusGraphMultiVertexQuery

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();
}
Also used : JanusGraphMultiVertexQuery(org.janusgraph.core.JanusGraphMultiVertexQuery) JanusGraphVertex(org.janusgraph.core.JanusGraphVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) JanusGraphElement(org.janusgraph.core.JanusGraphElement) BasicVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder) Iterator(java.util.Iterator) JanusGraphVertexQuery(org.janusgraph.core.JanusGraphVertexQuery) HashSet(java.util.HashSet)

Example 5 with JanusGraphMultiVertexQuery

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());
}
Also used : JanusGraphMultiVertexQuery(org.janusgraph.core.JanusGraphMultiVertexQuery) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) BasicVertexCentricQueryBuilder(org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder) Traverser(org.apache.tinkerpop.gremlin.process.traversal.Traverser) ArrayList(java.util.ArrayList) Edge(org.apache.tinkerpop.gremlin.structure.Edge) HashSet(java.util.HashSet)

Aggregations

JanusGraphMultiVertexQuery (org.janusgraph.core.JanusGraphMultiVertexQuery)5 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)4 JanusGraphVertex (org.janusgraph.core.JanusGraphVertex)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TraversalInterruptedException (org.apache.tinkerpop.gremlin.process.traversal.util.TraversalInterruptedException)2 JanusGraphException (org.janusgraph.core.JanusGraphException)2 BasicVertexCentricQueryBuilder (org.janusgraph.graphdb.query.vertex.BasicVertexCentricQueryBuilder)2 Iterator (java.util.Iterator)1 Traverser (org.apache.tinkerpop.gremlin.process.traversal.Traverser)1 Edge (org.apache.tinkerpop.gremlin.structure.Edge)1 JanusGraphElement (org.janusgraph.core.JanusGraphElement)1 JanusGraphVertexQuery (org.janusgraph.core.JanusGraphVertexQuery)1