Search in sources :

Example 1 with UnionStep

use of org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep 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)

Aggregations

Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)1 TraversalParent (org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent)1 RepeatStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep)1 UnionStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep)1 Graph (org.apache.tinkerpop.gremlin.structure.Graph)1 UniGraph (org.unipop.structure.UniGraph)1