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