Search in sources :

Example 1 with StepDescriptor

use of org.unipop.query.StepDescriptor in project unipop by unipop-graph.

the class UniGraphVertexStep method process.

@Override
protected Iterator<Traverser.Admin<E>> process(List<Traverser.Admin<Vertex>> traversers) {
    Map<Object, List<Traverser<Vertex>>> idToTraverser = new HashMap<>(traversers.size());
    List<Vertex> vertices = new ArrayList<>(traversers.size());
    traversers.forEach(traverser -> {
        Vertex vertex = traverser.get();
        List<Traverser<Vertex>> traverserList = idToTraverser.get(vertex.id());
        if (traverserList == null) {
            traverserList = new ArrayList<>(1);
            idToTraverser.put(vertex.id(), traverserList);
        }
        traverserList.add(traverser);
        vertices.add(vertex);
    });
    SearchVertexQuery vertexQuery;
    if (!returnsVertex)
        vertexQuery = new SearchVertexQuery(Edge.class, vertices, direction, predicates, limit, propertyKeys, orders, stepDescriptor, traversal);
    else
        vertexQuery = new SearchVertexQuery(Edge.class, vertices, direction, predicates, -1, propertyKeys, null, stepDescriptor, traversal);
    logger.debug("Executing query: ", vertexQuery);
    Iterator<Traverser.Admin<E>> traversersIterator = controllers.stream().<Iterator<Edge>>map(controller -> controller.search(vertexQuery)).<Edge>flatMap(ConversionUtils::asStream).<Traverser.Admin<E>>flatMap(edge -> toTraversers(edge, idToTraverser)).iterator();
    if (!this.returnsVertex || (propertyKeys != null && propertyKeys.size() == 0))
        return traversersIterator;
    return getTraversersWithProperties(traversersIterator);
}
Also used : org.apache.tinkerpop.gremlin.process.traversal(org.apache.tinkerpop.gremlin.process.traversal) java.util(java.util) Attachable(org.apache.tinkerpop.gremlin.structure.util.Attachable) LoggerFactory(org.slf4j.LoggerFactory) EmptyIterator(org.apache.tinkerpop.gremlin.util.iterator.EmptyIterator) org.apache.tinkerpop.gremlin.process.traversal.step.util(org.apache.tinkerpop.gremlin.process.traversal.step.util) PredicatesHolderFactory(org.unipop.query.predicates.PredicatesHolderFactory) Orderable(org.unipop.process.order.Orderable) Profiling(org.apache.tinkerpop.gremlin.process.traversal.step.Profiling) org.apache.tinkerpop.gremlin.structure(org.apache.tinkerpop.gremlin.structure) MutableMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics) PredicatesHolder(org.unipop.query.predicates.PredicatesHolder) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) ConversionUtils(org.unipop.util.ConversionUtils) DeferredVertex(org.unipop.schema.reference.DeferredVertex) Logger(org.slf4j.Logger) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) ReceivesPredicatesHolder(org.unipop.process.predicate.ReceivesPredicatesHolder) StepDescriptor(org.unipop.query.StepDescriptor) Stream(java.util.stream.Stream) TraverserRequirement(org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement) ControllerManager(org.unipop.query.controller.ControllerManager) UniGraph(org.unipop.structure.UniGraph) StringFactory(org.apache.tinkerpop.gremlin.structure.util.StringFactory) UniPredicatesStep(org.unipop.process.UniPredicatesStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery) UniVertex(org.unipop.structure.UniVertex) ConversionUtils(org.unipop.util.ConversionUtils) DeferredVertex(org.unipop.schema.reference.DeferredVertex) UniVertex(org.unipop.structure.UniVertex) SearchVertexQuery(org.unipop.query.search.SearchVertexQuery)

Example 2 with StepDescriptor

use of org.unipop.query.StepDescriptor in project unipop by unipop-graph.

the class UniGraphEdgeOtherVertexStep method process.

@Override
protected Iterator<Traverser.Admin<Vertex>> process(List<Traverser.Admin<Edge>> traversers) {
    List<Traverser.Admin<Vertex>> vertices = new ArrayList<>();
    traversers.forEach(traverser -> {
        final List<Object> objects = traverser.path().objects();
        if (objects.get(objects.size() - 2) instanceof Vertex) {
            Vertex vertex = ElementHelper.areEqual((Vertex) objects.get(objects.size() - 2), traverser.get().outVertex()) ? traverser.get().inVertex() : traverser.get().outVertex();
            vertices.add(traverser.split(vertex, this));
        }
    });
    if (propertyKeys == null || propertyKeys.size() > 0) {
        List<DeferredVertex> v = vertices.stream().map(Attachable::get).filter(vertex -> vertex instanceof DeferredVertex).map(vertex -> ((DeferredVertex) vertex)).filter(DeferredVertex::isDeferred).collect(Collectors.toList());
        if (v.size() > 0) {
            DeferredVertexQuery query = new DeferredVertexQuery(v, propertyKeys, orders, stepDescriptor, traversal);
            deferredVertexControllers.forEach(deferredVertexController -> deferredVertexController.fetchProperties(query));
        }
    }
    return vertices.iterator();
}
Also used : DeferredVertex(org.unipop.schema.reference.DeferredVertex) java.util(java.util) Attachable(org.apache.tinkerpop.gremlin.structure.util.Attachable) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) ElementHelper(org.apache.tinkerpop.gremlin.structure.util.ElementHelper) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) StepDescriptor(org.unipop.query.StepDescriptor) Traverser(org.apache.tinkerpop.gremlin.process.traversal.Traverser) Order(org.apache.tinkerpop.gremlin.process.traversal.Order) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) Orderable(org.unipop.process.order.Orderable) Profiling(org.apache.tinkerpop.gremlin.process.traversal.step.Profiling) TraverserRequirement(org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement) MutableMetrics(org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics) ControllerManager(org.unipop.query.controller.ControllerManager) UniGraph(org.unipop.structure.UniGraph) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) UniPredicatesStep(org.unipop.process.UniPredicatesStep) Edge(org.apache.tinkerpop.gremlin.structure.Edge) DeferredVertex(org.unipop.schema.reference.DeferredVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DeferredVertex(org.unipop.schema.reference.DeferredVertex) DeferredVertexQuery(org.unipop.query.search.DeferredVertexQuery) Attachable(org.apache.tinkerpop.gremlin.structure.util.Attachable)

Aggregations

java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Profiling (org.apache.tinkerpop.gremlin.process.traversal.step.Profiling)2 TraverserRequirement (org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement)2 MutableMetrics (org.apache.tinkerpop.gremlin.process.traversal.util.MutableMetrics)2 Attachable (org.apache.tinkerpop.gremlin.structure.util.Attachable)2 Pair (org.javatuples.Pair)2 UniPredicatesStep (org.unipop.process.UniPredicatesStep)2 Orderable (org.unipop.process.order.Orderable)2 StepDescriptor (org.unipop.query.StepDescriptor)2 ControllerManager (org.unipop.query.controller.ControllerManager)2 DeferredVertexQuery (org.unipop.query.search.DeferredVertexQuery)2 DeferredVertex (org.unipop.schema.reference.DeferredVertex)2 UniGraph (org.unipop.structure.UniGraph)2 Stream (java.util.stream.Stream)1 org.apache.tinkerpop.gremlin.process.traversal (org.apache.tinkerpop.gremlin.process.traversal)1 Order (org.apache.tinkerpop.gremlin.process.traversal.Order)1 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 Traverser (org.apache.tinkerpop.gremlin.process.traversal.Traverser)1 VertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep)1