Search in sources :

Example 1 with JanusGraphMultiQueryStep

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

the class JanusGraphMultiQueryStrategy method insertMultiQuerySteps.

/**
 * Insert JanusGraphMultiQuerySteps everywhere in the current traversal where MultiQueriable steps could benefit
 *
 * @param traversal The local traversal layer.
 */
private void insertMultiQuerySteps(final Admin<?, ?> traversal, boolean limitBatchSize) {
    JanusGraphTraversalUtil.getSteps(JanusGraphTraversalUtil::isMultiQueryCompatibleStep, traversal).forEach(step -> {
        Optional<Step> multiQueryPosition = JanusGraphTraversalUtil.getLocalMultiQueryPositionForStep(step);
        if (multiQueryPosition.isPresent() && JanusGraphTraversalUtil.isLegalMultiQueryPosition(multiQueryPosition.get())) {
            Step pos = multiQueryPosition.get();
            if (limitBatchSize && !(multiQueryPosition.get() instanceof NoOpBarrierStep)) {
                NoOpBarrierStep barrier = new NoOpBarrierStep(traversal);
                TraversalHelper.insertBeforeStep(barrier, pos, traversal);
                pos = barrier;
            }
            JanusGraphMultiQueryStep multiQueryStep = new JanusGraphMultiQueryStep(traversal, limitBatchSize);
            TraversalHelper.insertBeforeStep(multiQueryStep, pos, traversal);
        }
    });
}
Also used : JanusGraphMultiQueryStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep) NoOpBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep) NoOpBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) JanusGraphMultiQueryStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep) DropStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.DropStep)

Example 2 with JanusGraphMultiQueryStep

use of org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep 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)

Example 3 with JanusGraphMultiQueryStep

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

the class JanusGraphMultiQueryStepTest method testReset.

@ParameterizedTest
@MethodSource("generateTestParameters")
public void testReset(Traversal.Admin traversal, boolean limitBatchSize, Collection<MultiQueriable> clients) {
    JanusGraphMultiQueryStep originalStep = new JanusGraphMultiQueryStep(traversal, limitBatchSize);
    clients.forEach(originalStep::attachClient);
    originalStep.reset();
    assertEquals(limitBatchSize, originalStep.isLimitBatchSize());
    assertEquals(originalStep.getClientSteps().size(), clients.size());
    assertTrue(clients.containsAll(originalStep.getClientSteps()));
    assertTrue(originalStep.getClientSteps().containsAll(clients));
}
Also used : JanusGraphMultiQueryStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 4 with JanusGraphMultiQueryStep

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

the class JanusGraphMultiQueryStepTest method testClone.

@ParameterizedTest
@MethodSource("generateTestParameters")
public void testClone(Traversal.Admin traversal, boolean limitBatchSize, Collection<MultiQueriable> clients) {
    JanusGraphMultiQueryStep originalStep = new JanusGraphMultiQueryStep(traversal, limitBatchSize);
    clients.forEach(originalStep::attachClient);
    JanusGraphMultiQueryStep clone = originalStep.clone();
    assertEquals(limitBatchSize, clone.isLimitBatchSize());
    assertEquals(originalStep.getClientSteps().size(), clone.getClientSteps().size());
    assertTrue(clone.getClientSteps().containsAll(originalStep.getClientSteps()));
    assertTrue(originalStep.getClientSteps().containsAll(clone.getClientSteps()));
}
Also used : JanusGraphMultiQueryStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 5 with JanusGraphMultiQueryStep

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

the class JanusGraphMultiQueryStrategy method configureMultiQueriables.

/**
 * Looks for MultiQueriables in within the traversal and registers them as clients of their respective
 * JanusGraphMultiQuerySteps
 *
 * @param traversal The local traversal layer.
 */
private void configureMultiQueriables(final Admin<?, ?> traversal) {
    TraversalHelper.getStepsOfAssignableClass(MultiQueriable.class, traversal).forEach(multiQueriable -> {
        final List<Step> mqPositions = JanusGraphTraversalUtil.getAllMultiQueryPositionsForMultiQueriable(multiQueriable);
        // If one position is not legal, this means that the entire step can not use the multiQuery feature.
        for (Step mqPos : mqPositions) {
            if (!JanusGraphTraversalUtil.isLegalMultiQueryPosition(mqPos)) {
                return;
            }
        }
        // MultiQuery is applicable
        multiQueriable.setUseMultiQuery(true);
        for (Step mqPos : mqPositions) {
            final Optional<JanusGraphMultiQueryStep> multiQueryStep = JanusGraphTraversalUtil.getPreviousStepOfClass(JanusGraphMultiQueryStep.class, mqPos);
            multiQueryStep.ifPresent(mqs -> mqs.attachClient(multiQueriable));
        }
    });
}
Also used : MultiQueriable(org.janusgraph.graphdb.tinkerpop.optimize.step.MultiQueriable) JanusGraphMultiQueryStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep) NoOpBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep) Step(org.apache.tinkerpop.gremlin.process.traversal.Step) JanusGraphMultiQueryStep(org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep) DropStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.DropStep)

Aggregations

JanusGraphMultiQueryStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphMultiQueryStep)5 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)2 DropStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.DropStep)2 NoOpBarrierStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MethodSource (org.junit.jupiter.params.provider.MethodSource)2 IsStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep)1 PropertiesStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep)1 VertexStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep)1 JanusGraphPropertiesStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphPropertiesStep)1 JanusGraphVertexStep (org.janusgraph.graphdb.tinkerpop.optimize.step.JanusGraphVertexStep)1 MultiQueriable (org.janusgraph.graphdb.tinkerpop.optimize.step.MultiQueriable)1