use of org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep 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);
}
});
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep in project grakn by graknlabs.
the class JanusPreviousPropertyStepStrategy method apply.
@Override
public void apply(Traversal.Admin<?, ?> traversal) {
// Retrieve all graph (`V()`) steps - this is the step the strategy should replace
List<GraphStep> graphSteps = TraversalHelper.getStepsOfAssignableClass(GraphStep.class, traversal);
for (GraphStep graphStep : graphSteps) {
if (!(graphStep.getNextStep() instanceof TraversalFilterStep))
continue;
TraversalFilterStep<Vertex> filterStep = (TraversalFilterStep<Vertex>) graphStep.getNextStep();
// Retrieve the filter steps e.g. `__.properties(a).where(P.eq(b))`
List<Step> steps = stepsFromFilterStep(filterStep);
if (steps.size() < 2)
continue;
// This is `properties(a)`
Step propertiesStep = steps.get(0);
// This is `filter(__.where(P.eq(b)))`
Step whereStep = steps.get(1);
// Get the property key `a`
if (!(propertiesStep instanceof PropertiesStep))
continue;
Optional<String> propertyKey = propertyFromPropertiesStep((PropertiesStep<Vertex>) propertiesStep);
if (!propertyKey.isPresent())
continue;
// Get the step label `b`
if (!(whereStep instanceof WherePredicateStep))
continue;
Optional<String> label = labelFromWhereEqPredicate((WherePredicateStep<Vertex>) whereStep);
if (!label.isPresent())
continue;
executeStrategy(traversal, graphStep, filterStep, propertyKey.get(), label.get());
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep in project janusgraph by JanusGraph.
the class JanusGraphLocalQueryOptimizerStrategy method applyJanusGraphPropertiesSteps.
private void applyJanusGraphPropertiesSteps(Admin<?, ?> traversal) {
TraversalHelper.getStepsOfAssignableClass(PropertiesStep.class, traversal).forEach(originalStep -> {
final JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep(originalStep);
TraversalHelper.replaceStep(originalStep, propertiesStep, originalStep.getTraversal());
if (propertiesStep.getReturnType().forProperties()) {
HasStepFolder.foldInHasContainer(propertiesStep, originalStep.getTraversal(), originalStep.getTraversal());
// We cannot fold in orders or ranges since they are not local
}
});
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep 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);
}
});
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep in project janusgraph by JanusGraph.
the class JanusGraphLocalQueryOptimizerStrategy 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.
StandardJanusGraph janusGraph = graph instanceof StandardJanusGraphTx ? ((StandardJanusGraphTx) graph).getGraph() : (StandardJanusGraph) graph;
final boolean useMultiQuery = !TraversalHelper.onGraphComputer(traversal) && janusGraph.getConfiguration().useMultiQuery();
/*
====== VERTEX STEP ======
*/
TraversalHelper.getStepsOfClass(VertexStep.class, traversal).forEach(originalStep -> {
JanusGraphVertexStep vertexStep = new JanusGraphVertexStep(originalStep);
TraversalHelper.replaceStep(originalStep, vertexStep, traversal);
if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
HasStepFolder.foldInHasContainer(vertexStep, traversal);
// We cannot fold in orders or ranges since they are not local
}
assert JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep) || JanusGraphTraversalUtil.isVertexReturnStep(vertexStep);
Step nextStep = JanusGraphTraversalUtil.getNextNonIdentityStep(vertexStep);
if (nextStep instanceof RangeGlobalStep) {
int limit = QueryUtil.convertLimit(((RangeGlobalStep) nextStep).getHighRange());
vertexStep.setLimit(QueryUtil.mergeLimits(limit, vertexStep.getLimit()));
}
if (useMultiQuery) {
vertexStep.setUseMultiQuery(true);
}
});
/*
====== PROPERTIES STEP ======
*/
TraversalHelper.getStepsOfClass(PropertiesStep.class, traversal).forEach(originalStep -> {
JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep(originalStep);
TraversalHelper.replaceStep(originalStep, propertiesStep, traversal);
if (propertiesStep.getReturnType().forProperties()) {
HasStepFolder.foldInHasContainer(propertiesStep, traversal);
// We cannot fold in orders or ranges since they are not local
}
if (useMultiQuery) {
propertiesStep.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) {
JanusGraphVertexStep vertexStep = new JanusGraphVertexStep((VertexStep) localStart);
TraversalHelper.replaceStep(localStart, vertexStep, localTraversal);
if (JanusGraphTraversalUtil.isEdgeReturnStep(vertexStep)) {
HasStepFolder.foldInHasContainer(vertexStep, localTraversal);
HasStepFolder.foldInOrder(vertexStep, localTraversal, traversal, false);
}
HasStepFolder.foldInRange(vertexStep, localTraversal);
unfoldLocalTraversal(traversal, localStep, localTraversal, vertexStep, useMultiQuery);
}
if (localStart instanceof PropertiesStep) {
JanusGraphPropertiesStep propertiesStep = new JanusGraphPropertiesStep((PropertiesStep) localStart);
TraversalHelper.replaceStep(localStart, propertiesStep, localTraversal);
if (propertiesStep.getReturnType().forProperties()) {
HasStepFolder.foldInHasContainer(propertiesStep, localTraversal);
HasStepFolder.foldInOrder(propertiesStep, localTraversal, traversal, false);
}
HasStepFolder.foldInRange(propertiesStep, localTraversal);
unfoldLocalTraversal(traversal, localStep, localTraversal, propertiesStep, useMultiQuery);
}
});
}
Aggregations