Search in sources :

Example 1 with EdgeVertexStep

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);
                    }
                }
            }
        }
    });
}
Also used : TitanVertex(com.thinkaurelius.titan.core.TitanVertex) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TitanVertex(com.thinkaurelius.titan.core.TitanVertex) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) EdgeVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep) EdgeOtherVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) EdgeOtherVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep) EdgeVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep) IsStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep) IdentityStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep) GraphStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GraphStep) TraversalFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) Direction(org.apache.tinkerpop.gremlin.structure.Direction) EdgeOtherVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep) EdgeVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) TraversalFilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep) IdentityStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep) IsStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep)

Aggregations

TitanVertex (com.thinkaurelius.titan.core.TitanVertex)1 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)1 IsStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep)1 TraversalFilterStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep)1 EdgeOtherVertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep)1 EdgeVertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep)1 VertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep)1 GraphStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GraphStep)1 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)1 Direction (org.apache.tinkerpop.gremlin.structure.Direction)1 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)1