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);
}
});
}
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());
}
});
}
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));
}
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()));
}
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));
}
});
}
Aggregations