use of org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep in project titan by thinkaurelius.
the class AdjacentVertexFilterOptimizerStrategy method apply.
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
TraversalHelper.getStepsOfClass(TraversalFilterStep.class, traversal).forEach(originalStep -> {
Traversal.Admin<?, ?> filterTraversal = (Traversal.Admin<?, ?>) originalStep.getLocalChildren().get(0);
List<Step> steps = filterTraversal.getSteps();
if (steps.size() == 2 && (steps.get(0) instanceof EdgeVertexStep || steps.get(0) instanceof EdgeOtherVertexStep) && (steps.get(1) instanceof IsStep)) {
Direction direction = null;
if (steps.get(0) instanceof EdgeVertexStep) {
EdgeVertexStep evs = (EdgeVertexStep) steps.get(0);
if (evs.getDirection() != Direction.BOTH)
direction = evs.getDirection();
} else {
assert steps.get(0) instanceof EdgeOtherVertexStep;
direction = Direction.BOTH;
}
P predicate = ((IsStep) steps.get(1)).getPredicate();
if (direction != null && predicate.getBiPredicate() == Compare.eq && predicate.getValue() instanceof Vertex) {
TitanVertex vertex = TitanTraversalUtil.getTitanVertex((Vertex) predicate.getValue());
Step<?, ?> currentStep = originalStep.getPreviousStep();
while (true) {
if (currentStep instanceof HasStep || currentStep instanceof IdentityStep) {
} else
break;
}
if (currentStep instanceof VertexStep) {
VertexStep vstep = (VertexStep) currentStep;
if (vstep.returnsEdge() && (direction == Direction.BOTH || direction.equals(vstep.getDirection().opposite()))) {
TraversalHelper.replaceStep(originalStep, new HasStep(traversal, HasContainer.makeHasContainers(ImplicitKey.ADJACENT_ID.name(), P.eq(vertex))), traversal);
}
}
}
}
});
}
Aggregations