Search in sources :

Example 1 with JanusGraphVertexStep

use of org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep in project janusgraph by JanusGraph.

the class JanusGraphLocalQueryOptimizerStrategy method applyJanusGraphVertexSteps.

private void applyJanusGraphVertexSteps(Admin<?, ?> traversal, boolean batchPropertyPrefetching, int txVertexCacheSize) {
    TraversalHelper.getStepsOfAssignableClass(VertexStep.class, traversal).forEach(originalStep -> {
        final JanusGraphVertexStep vertexStep = new JanusGraphVertexStep(originalStep);
        TraversalHelper.replaceStep(originalStep, vertexStep, originalStep.getTraversal());
        if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
            HasStepFolder.foldInHasContainer(vertexStep, originalStep.getTraversal(), originalStep.getTraversal());
        // We cannot fold in orders or ranges since they are not local
        }
        assert JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep) || JanusGraphTraversalUtil.isVertexReturnStep(vertexStep);
        final Step nextStep = JanusGraphTraversalUtil.getNextNonIdentityStep(vertexStep);
        if (nextStep instanceof RangeGlobalStep) {
            final int limit = QueryUtil.convertLimit(((RangeGlobalStep) nextStep).getHighRange());
            vertexStep.setLimit(0, QueryUtil.mergeHighLimits(limit, vertexStep.getHighLimit()));
        }
        if (batchPropertyPrefetching) {
            applyBatchPropertyPrefetching(originalStep.getTraversal(), vertexStep, nextStep, txVertexCacheSize);
        }
    });
}
Also used : EdgeVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) JanusGraphEdgeVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphEdgeVertexStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) EdgeVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep) 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) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) JanusGraphEdgeVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphEdgeVertexStep) JanusGraphPropertiesStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep)

Example 2 with JanusGraphVertexStep

use of org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep in project janusgraph by JanusGraph.

the class JanusGraphLocalQueryOptimizerStrategy method inspectLocalTraversals.

private void inspectLocalTraversals(final Admin<?, ?> traversal) {
    TraversalHelper.getStepsOfClass(LocalStep.class, traversal).forEach(localStep -> {
        final Admin localTraversal = ((LocalStep<?, ?>) localStep).getLocalChildren().get(0);
        final Step localStart = localTraversal.getStartStep();
        if (localStart instanceof VertexStep) {
            final JanusGraphVertexStep vertexStep = new JanusGraphVertexStep((VertexStep) localStart);
            TraversalHelper.replaceStep(localStart, vertexStep, localTraversal);
            if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
                HasStepFolder.foldInHasContainer(vertexStep, localTraversal, traversal);
                HasStepFolder.foldInOrder(vertexStep, vertexStep.getNextStep(), localTraversal, traversal, false, null);
            }
            HasStepFolder.foldInRange(vertexStep, JanusGraphTraversalUtil.getNextNonIdentityStep(vertexStep), localTraversal, null);
            unfoldLocalTraversal(traversal, localStep, localTraversal, vertexStep);
        }
        if (localStart instanceof PropertiesStep) {
            final JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep((PropertiesStep) localStart);
            TraversalHelper.replaceStep(localStart, propertiesStep, localTraversal);
            if (propertiesStep.getReturnType().forProperties()) {
                HasStepFolder.foldInHasContainer(propertiesStep, localTraversal, traversal);
                HasStepFolder.foldInOrder(propertiesStep, propertiesStep.getNextStep(), localTraversal, traversal, false, null);
            }
            HasStepFolder.foldInRange(propertiesStep, JanusGraphTraversalUtil.getNextNonIdentityStep(propertiesStep), localTraversal, null);
            unfoldLocalTraversal(traversal, localStep, localTraversal, propertiesStep);
        }
    });
}
Also used : EdgeVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) JanusGraphEdgeVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphEdgeVertexStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) PropertiesStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep) JanusGraphPropertiesStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep) EdgeVertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep) 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) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) JanusGraphEdgeVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphEdgeVertexStep) JanusGraphPropertiesStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) LocalStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep) Admin(org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) JanusGraphPropertiesStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep)

Example 3 with JanusGraphVertexStep

use of org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep in project janusgraph by JanusGraph.

the class JanusGraphStepStrategyTest method applyMultiQueryTraversalSteps.

private void applyMultiQueryTraversalSteps(Traversal.Admin<?, ?> traversal) {
    TraversalHelper.getStepsOfAssignableClassRecursively(VertexStep.class, traversal).forEach(vertexStep -> {
        JanusGraphVertexStep janusGraphVertexStep = new JanusGraphVertexStep<>(vertexStep);
        TraversalHelper.replaceStep(vertexStep, janusGraphVertexStep, vertexStep.getTraversal());
        if (JanusGraphTraversalUtil.isEdgeReturnStep(janusGraphVertexStep)) {
            HasStepFolder.foldInHasContainer(janusGraphVertexStep, vertexStep.getTraversal(), vertexStep.getTraversal());
        }
    });
    TraversalHelper.getStepsOfAssignableClassRecursively(PropertiesStep.class, traversal).forEach(vertexStep -> {
        JanusGraphPropertiesStep janusGraphPropertiesStep = new JanusGraphPropertiesStep<>(vertexStep);
        TraversalHelper.replaceStep(vertexStep, janusGraphPropertiesStep, vertexStep.getTraversal());
    });
    TraversalHelper.getStepsOfAssignableClassRecursively(IsStep.class, traversal).forEach(isStep -> {
        Object expectedStep = isStep.getPredicate().getValue();
        if (expectedStep.equals(JanusGraphMultiQueryStep.class.getSimpleName())) {
            TraversalHelper.replaceStep(isStep, new JanusGraphMultiQueryStep(isStep.getTraversal(), false), isStep.getTraversal());
        }
    });
}
Also used : JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) VertexStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep) JanusGraphPropertiesStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep) PropertiesStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep) JanusGraphMultiQueryStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep) IsStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep) JanusGraphVertexStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep) JanusGraphPropertiesStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep)

Aggregations

PropertiesStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep)3 VertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep)3 JanusGraphPropertiesStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep)3 JanusGraphVertexStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep)3 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)2 LocalStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep)2 RangeGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep)2 EdgeVertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep)2 JanusGraphEdgeVertexStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphEdgeVertexStep)2 Admin (org.apache.tinkerpop.gremlin.process.traversal.Traversal.Admin)1 IsStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep)1 JanusGraphMultiQueryStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep)1