use of org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep in project janusgraph by JanusGraph.
the class HasStepFolder method foldInIds.
static void foldInIds(final HasStepFolder janusgraphStep, final Traversal.Admin<?, ?> traversal) {
Step<?, ?> currentStep = janusgraphStep.getNextStep();
while (true) {
if (currentStep instanceof HasContainerHolder) {
final HasContainerHolder hasContainerHolder = (HasContainerHolder) currentStep;
final GraphStep graphStep = (GraphStep) janusgraphStep;
// HasContainer collection that we get back is immutable so we keep track of which containers
// need to be deleted after they've been folded into the JanusGraphStep and then remove them from their
// step using HasContainer.removeHasContainer
final List<HasContainer> removableHasContainers = new ArrayList<>();
final Set<String> stepLabels = currentStep.getLabels();
hasContainerHolder.getHasContainers().forEach(hasContainer -> {
if (GraphStep.processHasContainerIds(graphStep, hasContainer)) {
stepLabels.forEach(janusgraphStep::addLabel);
// this has container is no longer needed because its ids will be folded into the JanusGraphStep
removableHasContainers.add(hasContainer);
}
});
if (!removableHasContainers.isEmpty()) {
removableHasContainers.forEach(hasContainerHolder::removeHasContainer);
}
// if all has containers have been removed, the current step can be removed
if (hasContainerHolder.getHasContainers().isEmpty()) {
traversal.removeStep(currentStep);
}
} else if (currentStep instanceof IdentityStep) {
// do nothing, has no impact
} else if (currentStep instanceof NoOpBarrierStep) {
// do nothing, has no impact
} else {
break;
}
currentStep = currentStep.getNextStep();
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep in project janusgraph by JanusGraph.
the class HasStepFolder method foldInOrder.
static void foldInOrder(final HasStepFolder janusgraphStep, final Traversal.Admin<?, ?> traversal, final Traversal<?, ?> rootTraversal, boolean isVertexOrder) {
Step<?, ?> currentStep = janusgraphStep.getNextStep();
OrderGlobalStep<?, ?> lastOrder = null;
while (true) {
if (currentStep instanceof OrderGlobalStep) {
if (lastOrder != null) {
// Previous orders are rendered irrelevant by next order (since re-ordered)
lastOrder.getLabels().forEach(janusgraphStep::addLabel);
traversal.removeStep(lastOrder);
}
lastOrder = (OrderGlobalStep) currentStep;
} else if (!(currentStep instanceof IdentityStep) && !(currentStep instanceof HasStep) && !(currentStep instanceof NoOpBarrierStep)) {
break;
}
currentStep = currentStep.getNextStep();
}
if (lastOrder != null) {
if (validJanusGraphOrder(lastOrder, rootTraversal, isVertexOrder)) {
// Add orders to HasStepFolder
for (Pair<Traversal.Admin<Object, Comparable>, Comparator<Object>> comp : (List<Pair<Traversal.Admin<Object, Comparable>, Comparator<Object>>>) ((OrderGlobalStep) lastOrder).getComparators()) {
ElementValueTraversal evt = (ElementValueTraversal) comp.getValue0();
janusgraphStep.orderBy(evt.getPropertyKey(), (Order) comp.getValue1());
}
lastOrder.getLabels().forEach(janusgraphStep::addLabel);
traversal.removeStep(lastOrder);
}
}
}
Aggregations