Search in sources :

Example 1 with TraversalParent

use of org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent in project unipop by unipop-graph.

the class UniGraphUnionStepStrategy method apply.

@Override
public void apply(Traversal.Admin<?, ?> traversal) {
    Graph graph = traversal.getGraph().get();
    if (!(graph instanceof UniGraph)) {
        return;
    }
    UniGraph uniGraph = (UniGraph) graph;
    TraversalHelper.getStepsOfClass(UnionStep.class, traversal).forEach(unionStep -> {
        Traversal.Admin[] traversals = (Traversal.Admin[]) unionStep.getGlobalChildren().toArray(new Traversal.Admin[0]);
        for (Traversal.Admin admin : traversals) {
            if (TraversalHelper.getLastStepOfAssignableClass(ReducingBarrierStep.class, admin).isPresent() || traversal.getParent() instanceof RepeatStep)
                return;
        }
        UniGraphUnionStep uniGraphUnionStep = new UniGraphUnionStep(traversal, uniGraph, traversals);
        if (TraversalHelper.stepIndex(unionStep, traversal) != -1) {
            TraversalHelper.replaceStep(unionStep, uniGraphUnionStep, traversal);
        } else {
            TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, traversal).forEach(traversalParent -> {
                traversalParent.getLocalChildren().forEach(child -> {
                    if (TraversalHelper.stepIndex(unionStep, child) != -1) {
                        TraversalHelper.replaceStep(unionStep, uniGraphUnionStep, child);
                    }
                });
                traversalParent.getGlobalChildren().forEach(child -> {
                    if (TraversalHelper.stepIndex(unionStep, child) != -1) {
                        TraversalHelper.replaceStep(unionStep, uniGraphUnionStep, child);
                    }
                });
            });
        }
    });
}
Also used : UniGraph(org.unipop.structure.UniGraph) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) Graph(org.apache.tinkerpop.gremlin.structure.Graph) UniGraph(org.unipop.structure.UniGraph) RepeatStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) UnionStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep)

Example 2 with TraversalParent

use of org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent in project unipop by unipop-graph.

the class UniGraphPropertiesStrategy method getAllPropertyFetchersOf.

private List<PropertyFetcher> getAllPropertyFetchersOf(Step step, Traversal.Admin<?, ?> traversal) {
    List<PropertyFetcher> propertyFetchers = new ArrayList<>();
    Step previous = step.getPreviousStep();
    while (!(previous instanceof EmptyStep)) {
        if (previous instanceof PropertyFetcher)
            propertyFetchers.add((PropertyFetcher) previous);
        if (previous instanceof TraversalParent) {
            ((TraversalParent) previous).getLocalChildren().forEach(t -> t.getSteps().stream().filter(s -> s instanceof PropertyFetcher).map(p -> ((PropertyFetcher) p)).forEach(propertyFetchers::add));
            ((TraversalParent) previous).getGlobalChildren().forEach(t -> t.getSteps().stream().filter(s -> s instanceof PropertyFetcher).map(p -> ((PropertyFetcher) p)).forEach(propertyFetchers::add));
        }
        previous = previous.getPreviousStep();
    }
    return propertyFetchers;
}
Also used : EmptyStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep) java.util(java.util) EdgeStepsStrategy(org.unipop.process.edge.EdgeStepsStrategy) UniGraphStepStrategy(org.unipop.process.graph.UniGraphStepStrategy) SideEffectStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectStep) UniGraphEdgeOtherVertexStep(org.unipop.process.edge.UniGraphEdgeOtherVertexStep) ElementValueTraversal(org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) UniGraphEdgeVertexStep(org.unipop.process.edge.UniGraphEdgeVertexStep) P(org.apache.tinkerpop.gremlin.process.traversal.P) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) org.apache.tinkerpop.gremlin.process.traversal.step.map(org.apache.tinkerpop.gremlin.process.traversal.step.map) TraversalHelper(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) org.apache.tinkerpop.gremlin.process.traversal.step.filter(org.apache.tinkerpop.gremlin.process.traversal.step.filter) UniGraphVertexStepStrategy(org.unipop.process.vertex.UniGraphVertexStepStrategy) TraversalStrategy(org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy) UniGraphRepeatStepStrategy(org.unipop.process.repeat.UniGraphRepeatStepStrategy) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) ReducingBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep) TreeSideEffectStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.TreeSideEffectStep) Stream(java.util.stream.Stream) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) AbstractTraversalStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) UniGraphWhereTraversalStep(org.unipop.process.where.UniGraphWhereTraversalStep) UniGraphRepeatStep(org.unipop.process.repeat.UniGraphRepeatStep) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) EmptyStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep) EmptyStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep) SideEffectStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectStep) UniGraphEdgeOtherVertexStep(org.unipop.process.edge.UniGraphEdgeOtherVertexStep) UniGraphEdgeVertexStep(org.unipop.process.edge.UniGraphEdgeVertexStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) ReducingBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep) TreeSideEffectStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.TreeSideEffectStep) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) UniGraphWhereTraversalStep(org.unipop.process.where.UniGraphWhereTraversalStep) UniGraphRepeatStep(org.unipop.process.repeat.UniGraphRepeatStep)

Example 3 with TraversalParent

use of org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent in project unipop by unipop-graph.

the class UniGraphVertexStepStrategy method apply.

@Override
public void apply(Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;
    Graph graph = traversal.getGraph().get();
    if (!(graph instanceof UniGraph)) {
        return;
    }
    UniGraph uniGraph = (UniGraph) graph;
    TraversalHelper.getStepsOfAssignableClassRecursively(VertexStep.class, traversal).forEach(vertexStep -> {
        if (TraversalHelper.stepIndex(vertexStep, traversal) != -1) {
            UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
            TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, traversal);
            if (vertexStep.returnsEdge())
                PredicatesUtil.collectPredicates(uniGraphVertexStep, traversal);
        } else {
            TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, traversal).forEach(traversalParent -> {
                traversalParent.getLocalChildren().forEach(child -> {
                    if (TraversalHelper.stepIndex(vertexStep, child) != -1) {
                        UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
                        TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child);
                        if (vertexStep.returnsEdge())
                            PredicatesUtil.collectPredicates(uniGraphVertexStep, child);
                    }
                });
                traversalParent.getGlobalChildren().forEach(child -> {
                    if (TraversalHelper.stepIndex(vertexStep, child) != -1) {
                        UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
                        TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child);
                        if (vertexStep.returnsEdge())
                            PredicatesUtil.collectPredicates(uniGraphVertexStep, child);
                    } else if (TraversalHelper.hasStepOfAssignableClass(TraversalParent.class, child)) {
                        TraversalHelper.getStepsOfAssignableClass(TraversalParent.class, child).forEach(traversalParent1 -> {
                            traversalParent.getLocalChildren().forEach(child1 -> {
                                if (TraversalHelper.stepIndex(vertexStep, child1) != -1) {
                                    UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
                                    TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child1);
                                    if (vertexStep.returnsEdge())
                                        PredicatesUtil.collectPredicates(uniGraphVertexStep, child1);
                                }
                            });
                            traversalParent.getGlobalChildren().forEach(child1 -> {
                                if (TraversalHelper.stepIndex(vertexStep, child1) != -1) {
                                    UniGraphVertexStep uniGraphVertexStep = new UniGraphVertexStep<>(vertexStep, uniGraph, uniGraph.getControllerManager());
                                    TraversalHelper.replaceStep(vertexStep, uniGraphVertexStep, child1);
                                    if (vertexStep.returnsEdge())
                                        PredicatesUtil.collectPredicates(uniGraphVertexStep, child1);
                                }
                            });
                        });
                    }
                });
            });
        }
    });
}
Also used : VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) TraversalHelper(org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper) AbstractTraversalStrategy(org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) Graph(org.apache.tinkerpop.gremlin.structure.Graph) UniGraph(org.unipop.structure.UniGraph) TraversalStrategy(org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) PredicatesUtil(org.unipop.process.predicate.PredicatesUtil) UniGraph(org.unipop.structure.UniGraph) TraversalParent(org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent) Graph(org.apache.tinkerpop.gremlin.structure.Graph) UniGraph(org.unipop.structure.UniGraph)

Aggregations

Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)3 TraversalParent (org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent)3 TraversalStrategy (org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy)2 AbstractTraversalStrategy (org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy)2 TraversalHelper (org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper)2 Graph (org.apache.tinkerpop.gremlin.structure.Graph)2 UniGraph (org.unipop.structure.UniGraph)2 Sets (com.google.common.collect.Sets)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 P (org.apache.tinkerpop.gremlin.process.traversal.P)1 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)1 DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)1 ElementValueTraversal (org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal)1 LocalStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep)1 RepeatStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep)1 UnionStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep)1 org.apache.tinkerpop.gremlin.process.traversal.step.filter (org.apache.tinkerpop.gremlin.process.traversal.step.filter)1 org.apache.tinkerpop.gremlin.process.traversal.step.map (org.apache.tinkerpop.gremlin.process.traversal.step.map)1