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);
}
});
});
}
});
}
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;
}
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);
}
});
});
}
});
});
}
});
}
Aggregations