Search in sources :

Example 1 with NoOpBarrierStep

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();
    }
}
Also used : IdentityStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep) HasContainerHolder(org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder) GraphStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep) HasContainer(org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer) ArrayList(java.util.ArrayList) NoOpBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep)

Example 2 with NoOpBarrierStep

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);
        }
    }
}
Also used : IdentityStep(org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep) HasStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep) OrderGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep) NoOpBarrierStep(org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep) ArrayList(java.util.ArrayList) List(java.util.List) ElementValueTraversal(org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal) Comparator(java.util.Comparator)

Aggregations

ArrayList (java.util.ArrayList)2 NoOpBarrierStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep)2 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)2 Comparator (java.util.Comparator)1 List (java.util.List)1 ElementValueTraversal (org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal)1 HasContainerHolder (org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder)1 HasStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep)1 GraphStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep)1 OrderGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep)1 HasContainer (org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer)1