Search in sources :

Example 1 with VertexStep

use of org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep in project titan by thinkaurelius.

the class FulgoraUtil method getReverseTraversal.

private static FulgoraElementTraversal<Vertex, Edge> getReverseTraversal(final MessageScope.Local<?> scope, final TitanTransaction graph, @Nullable final Vertex start) {
    Traversal.Admin<Vertex, Edge> incident = scope.getIncidentTraversal().get().asAdmin();
    FulgoraElementTraversal<Vertex, Edge> result = FulgoraElementTraversal.of(graph);
    for (Step step : incident.getSteps()) result.addStep(step);
    Step<Vertex, ?> startStep = result.getStartStep();
    assert startStep instanceof VertexStep;
    ((VertexStep) startStep).reverseDirection();
    if (start != null)
        result.addStep(0, new StartStep<>(incident, start));
    result.asAdmin().setStrategies(FULGORA_STRATEGIES);
    return result;
}
Also used : TitanVertexStep(com.thinkaurelius.titan.graphdb.tinkerpop.optimize.TitanVertexStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) StartStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.StartStep) TitanVertexStep(com.thinkaurelius.titan.graphdb.tinkerpop.optimize.TitanVertexStep) StartStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.StartStep) OrderLocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderLocalStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) FilterStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep) OrderGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep) IdentityStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

Example 2 with VertexStep

use of org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep in project titan by thinkaurelius.

the class TitanLocalQueryOptimizerStrategy method apply.

@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (!traversal.getGraph().isPresent())
        return;
    Graph graph = traversal.getGraph().get();
    //If this is a compute graph then we can't apply local traversal optimisation at this stage.
    StandardTitanGraph titanGraph = graph instanceof StandardTitanTx ? ((StandardTitanTx) graph).getGraph() : (StandardTitanGraph) graph;
    final boolean useMultiQuery = traversal.getEngine().isStandard() && titanGraph.getConfiguration().useMultiQuery();
    /*
                ====== VERTEX STEP ======
         */
    TraversalHelper.getStepsOfClass(VertexStep.class, traversal).forEach(originalStep -> {
        TitanVertexStep vstep = new TitanVertexStep(originalStep);
        TraversalHelper.replaceStep(originalStep, vstep, traversal);
        if (TitanTraversalUtil.isEdgeReturnStep(vstep)) {
            HasStepFolder.foldInHasContainer(vstep, traversal);
        }
        assert TitanTraversalUtil.isEdgeReturnStep(vstep) || TitanTraversalUtil.isVertexReturnStep(vstep);
        Step nextStep = TitanTraversalUtil.getNextNonIdentityStep(vstep);
        if (nextStep instanceof RangeGlobalStep) {
            int limit = QueryUtil.convertLimit(((RangeGlobalStep) nextStep).getHighRange());
            vstep.setLimit(QueryUtil.mergeLimits(limit, vstep.getLimit()));
        }
        if (useMultiQuery) {
            vstep.setUseMultiQuery(true);
        }
    });
    /*
                ====== PROPERTIES STEP ======
         */
    TraversalHelper.getStepsOfClass(PropertiesStep.class, traversal).forEach(originalStep -> {
        TitanPropertiesStep vstep = new TitanPropertiesStep(originalStep);
        TraversalHelper.replaceStep(originalStep, vstep, traversal);
        if (vstep.getReturnType().forProperties()) {
            HasStepFolder.foldInHasContainer(vstep, traversal);
        }
        if (useMultiQuery) {
            vstep.setUseMultiQuery(true);
        }
    });
    /*
                ====== EITHER INSIDE LOCAL ======
         */
    TraversalHelper.getStepsOfClass(LocalStep.class, traversal).forEach(localStep -> {
        Traversal.Admin localTraversal = ((LocalStep<?, ?>) localStep).getLocalChildren().get(0);
        Step localStart = localTraversal.getStartStep();
        if (localStart instanceof VertexStep) {
            TitanVertexStep vstep = new TitanVertexStep((VertexStep) localStart);
            TraversalHelper.replaceStep(localStart, vstep, localTraversal);
            if (TitanTraversalUtil.isEdgeReturnStep(vstep)) {
                HasStepFolder.foldInHasContainer(vstep, localTraversal);
                HasStepFolder.foldInOrder(vstep, localTraversal, traversal, false);
            }
            HasStepFolder.foldInRange(vstep, localTraversal);
            unfoldLocalTraversal(traversal, localStep, localTraversal, vstep, useMultiQuery);
        }
        if (localStart instanceof PropertiesStep) {
            TitanPropertiesStep vstep = new TitanPropertiesStep((PropertiesStep) localStart);
            TraversalHelper.replaceStep(localStart, vstep, localTraversal);
            if (vstep.getReturnType().forProperties()) {
                HasStepFolder.foldInHasContainer(vstep, localTraversal);
                HasStepFolder.foldInOrder(vstep, localTraversal, traversal, false);
            }
            HasStepFolder.foldInRange(vstep, localTraversal);
            unfoldLocalTraversal(traversal, localStep, localTraversal, vstep, useMultiQuery);
        }
    });
}
Also used : PropertiesStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep) Traversal(org.apache.tinkerpop.gremlin.process.traversal.Traversal) PropertiesStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) StandardTitanTx(com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) StandardTitanGraph(com.thinkaurelius.titan.graphdb.database.StandardTitanGraph) Graph(org.apache.tinkerpop.gremlin.structure.Graph) StandardTitanGraph(com.thinkaurelius.titan.graphdb.database.StandardTitanGraph) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep)

Example 3 with VertexStep

use of org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep 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

VertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep)3 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)2 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)2 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 TitanVertex (com.thinkaurelius.titan.core.TitanVertex)1 StandardTitanGraph (com.thinkaurelius.titan.graphdb.database.StandardTitanGraph)1 TitanVertexStep (com.thinkaurelius.titan.graphdb.tinkerpop.optimize.TitanVertexStep)1 StandardTitanTx (com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx)1 LocalStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep)1 FilterStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep)1 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)1 IsStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep)1 RangeGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep)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 OrderGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep)1 OrderLocalStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderLocalStep)1 PropertiesStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep)1