org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HasStepFolder.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
static void localFoldInHasContainer(HasStepFolder janusgraphStep, Step<?, ?> tinkerpopStep, Traversal.Admin<?, ?> traversal, Traversal<?, ?> rootTraversal) {
    Step<?, ?> currentStep = tinkerpopStep;
    while (true) {
        if (currentStep instanceof HasContainerHolder) {
            Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers().stream().map(c -> JanusGraphPredicate.Converter.convert(c)).collect(Collectors.toList());
            List<HasContainer> hasContainers = janusgraphStep.addLocalAll(containers);
            currentStep.getLabels().forEach(janusgraphStep::addLabel);
            traversal.removeStep(currentStep);
            currentStep = foldInOrder(janusgraphStep, currentStep, traversal, rootTraversal, janusgraphStep instanceof JanusGraphStep && ((JanusGraphStep) janusgraphStep).returnsVertex(), hasContainers);
            foldInRange(janusgraphStep, currentStep, traversal, hasContainers);
        } else if (!(currentStep instanceof IdentityStep) && !(currentStep instanceof NoOpBarrierStep)) {
            break;
        }
        currentStep = currentStep.getNextStep();
    }
}
 
Example #2
Source File: Neo4jGraphStepStrategy.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
        final Neo4jGraphStep<?, ?> neo4jGraphStep = new Neo4jGraphStep<>(originalGraphStep);
        TraversalHelper.replaceStep(originalGraphStep, neo4jGraphStep, traversal);
        Step<?, ?> currentStep = neo4jGraphStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    if (!GraphStep.processHasContainerIds(neo4jGraphStep, hasContainer))
                        neo4jGraphStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
Example #3
Source File: TinkerGraphCountStrategy.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (!(traversal.isRoot()) || TraversalHelper.onGraphComputer(traversal))
        return;
    final List<Step> steps = traversal.getSteps();
    if (steps.size() < 2 ||
            !(steps.get(0) instanceof GraphStep) ||
            0 != ((GraphStep) steps.get(0)).getIds().length ||
            !(steps.get(steps.size() - 1) instanceof CountGlobalStep))
        return;
    for (int i = 1; i < steps.size() - 1; i++) {
        final Step current = steps.get(i);
        if (!(//current instanceof MapStep ||  // MapSteps will not necessarily emit an element as demonstrated in https://issues.apache.org/jira/browse/TINKERPOP-1958
                current instanceof IdentityStep ||
                current instanceof NoOpBarrierStep ||
                current instanceof CollectingBarrierStep) ||
                (current instanceof TraversalParent &&
                        TraversalHelper.anyStepRecursively(s -> (s instanceof SideEffectStep || s instanceof AggregateGlobalStep), (TraversalParent) current)))
            return;
    }
    final Class<? extends Element> elementClass = ((GraphStep<?, ?>) steps.get(0)).getReturnClass();
    TraversalHelper.removeAllSteps(traversal);
    traversal.addStep(new TinkerCountGlobalStep<>(traversal, elementClass));
}
 
Example #4
Source File: TinkerGraphStepStrategy.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;

    for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
        final TinkerGraphStep<?, ?> tinkerGraphStep = new TinkerGraphStep<>(originalGraphStep);
        TraversalHelper.replaceStep(originalGraphStep, tinkerGraphStep, traversal);
        Step<?, ?> currentStep = tinkerGraphStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    if (!GraphStep.processHasContainerIds(tinkerGraphStep, hasContainer))
                        tinkerGraphStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
Example #5
Source File: HBaseGraphStepStrategy.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
        final HBaseGraphStep<?, ?> hbaseGraphStep = new HBaseGraphStep<>(originalGraphStep);
        TraversalHelper.replaceStep(originalGraphStep, hbaseGraphStep, traversal);
        Step<?, ?> currentStep = hbaseGraphStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    if (!GraphStep.processHasContainerIds(hbaseGraphStep, hasContainer))
                        hbaseGraphStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
Example #6
Source File: HBaseVertexStepStrategy.java    From hgraphdb with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    for (final VertexStep originalVertexStep : TraversalHelper.getStepsOfClass(VertexStep.class, traversal)) {
        final HBaseVertexStep<?> hbaseVertexStep = new HBaseVertexStep<>(originalVertexStep);
        TraversalHelper.replaceStep(originalVertexStep, hbaseVertexStep, traversal);
        Step<?, ?> currentStep = hbaseVertexStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    hbaseVertexStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
Example #7
Source File: HasStepFolder.java    From grakn with GNU Affero General Public License v3.0 6 votes vote down vote up
static void foldInHasContainer(HasStepFolder janusgraphStep, Traversal.Admin<?, ?> traversal, Traversal<?, ?> rootTraversal) {
    Step<?, ?> currentStep = janusgraphStep.getNextStep();
    while (true) {
        if (currentStep instanceof OrStep && janusgraphStep instanceof JanusGraphStep) {
            for (Traversal.Admin<?, ?> child : ((OrStep<?>) currentStep).getLocalChildren()) {
                if (!validFoldInHasContainer(child.getStartStep(), false)) {
                    return;
                }
            }
            ((OrStep<?>) currentStep).getLocalChildren().forEach(t -> localFoldInHasContainer(janusgraphStep, t.getStartStep(), t, rootTraversal));
            traversal.removeStep(currentStep);
        } else if (currentStep instanceof HasContainerHolder) {
            Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers().stream().map(c -> JanusGraphPredicate.Converter.convert(c)).collect(Collectors.toList());
            if (validFoldInHasContainer(currentStep, true)) {
                janusgraphStep.addAll(containers);
                currentStep.getLabels().forEach(janusgraphStep::addLabel);
                traversal.removeStep(currentStep);
            }
        } else if (!(currentStep instanceof IdentityStep) && !(currentStep instanceof NoOpBarrierStep) && !(currentStep instanceof HasContainerHolder)) {
            break;
        }
        currentStep = currentStep.getNextStep();
    }
}
 
Example #8
Source File: BitsyTraversalStrategy.java    From bitsy with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
	for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
		final BitsyGraphStep<?, ?> bitsyGraphStep = new BitsyGraphStep<>(originalGraphStep);
		TraversalHelper.replaceStep(originalGraphStep, bitsyGraphStep, traversal);
		Step<?, ?> currentStep = bitsyGraphStep.getNextStep();
		while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
			if (currentStep instanceof HasStep) {
				for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
					if (!GraphStep.processHasContainerIds(bitsyGraphStep, hasContainer))
						bitsyGraphStep.addHasContainer(hasContainer);
				}
				TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
				traversal.removeStep(currentStep);
			}
			currentStep = currentStep.getNextStep();
		}
	}
}
 
Example #9
Source File: TinkerGraphCountStrategy.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (!(traversal.getParent() instanceof EmptyStep) || TraversalHelper.onGraphComputer(traversal))
        return;
    final List<Step> steps = traversal.getSteps();
    if (steps.size() < 2 ||
            !(steps.get(0) instanceof GraphStep) ||
            0 != ((GraphStep) steps.get(0)).getIds().length ||
            !(steps.get(steps.size() - 1) instanceof CountGlobalStep))
        return;
    for (int i = 1; i < steps.size() - 1; i++) {
        final Step current = steps.get(i);
        if (!(//current instanceof MapStep ||  // MapSteps will not necessarily emit an element as demonstrated in https://issues.apache.org/jira/browse/TINKERPOP-1958
                current instanceof IdentityStep ||
                current instanceof NoOpBarrierStep ||
                current instanceof CollectingBarrierStep) ||
                (current instanceof TraversalParent &&
                        TraversalHelper.anyStepRecursively(s -> (s instanceof SideEffectStep || s instanceof AggregateStep), (TraversalParent) current)))
            return;
    }
    final Class<? extends Element> elementClass = ((GraphStep<?, ?>) steps.get(0)).getReturnClass();
    TraversalHelper.removeAllSteps(traversal);
    traversal.addStep(new TinkerCountGlobalStep<>(traversal, elementClass));
}
 
Example #10
Source File: TinkerGraphStepStrategy.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;

    for (final GraphStep originalGraphStep : TraversalHelper.getStepsOfClass(GraphStep.class, traversal)) {
        final TinkerGraphStep<?, ?> tinkerGraphStep = new TinkerGraphStep<>(originalGraphStep);
        TraversalHelper.replaceStep(originalGraphStep, tinkerGraphStep, traversal);
        Step<?, ?> currentStep = tinkerGraphStep.getNextStep();
        while (currentStep instanceof HasStep || currentStep instanceof NoOpBarrierStep) {
            if (currentStep instanceof HasStep) {
                for (final HasContainer hasContainer : ((HasContainerHolder) currentStep).getHasContainers()) {
                    if (!GraphStep.processHasContainerIds(tinkerGraphStep, hasContainer))
                        tinkerGraphStep.addHasContainer(hasContainer);
                }
                TraversalHelper.copyLabels(currentStep, currentStep.getPreviousStep(), false);
                traversal.removeStep(currentStep);
            }
            currentStep = currentStep.getNextStep();
        }
    }
}
 
Example #11
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 6 votes vote down vote up
public static void extractHasContainer(HugeGraphStep<?, ?> newStep,
                                       Traversal.Admin<?, ?> traversal) {
    Step<?, ?> step = newStep;
    do {
        step = step.getNextStep();
        if (step instanceof HasStep) {
            HasContainerHolder holder = (HasContainerHolder) step;
            for (HasContainer has : holder.getHasContainers()) {
                if (!GraphStep.processHasContainerIds(newStep, has)) {
                    newStep.addHasContainer(has);
                }
            }
            TraversalHelper.copyLabels(step, step.getPreviousStep(), false);
            traversal.removeStep(step);
        }
    } while (step instanceof HasStep || step instanceof NoOpBarrierStep);
}
 
Example #12
Source File: HasStepFolder.java    From grakn with GNU Affero General Public License v3.0 5 votes vote down vote up
static boolean validFoldInHasContainer(Step<?, ?> tinkerpopStep, boolean defaultValue) {
    Step<?, ?> currentStep = tinkerpopStep;
    Boolean toReturn = null;
    while (!(currentStep instanceof EmptyStep)) {
        if (currentStep instanceof HasContainerHolder) {
            Iterable<HasContainer> containers = ((HasContainerHolder) currentStep).getHasContainers();
            toReturn = toReturn == null ? validJanusGraphHas(containers) : toReturn && validJanusGraphHas(containers);
        } else if (!(currentStep instanceof IdentityStep) && !(currentStep instanceof NoOpBarrierStep) && !(currentStep instanceof RangeGlobalStep) && !(currentStep instanceof OrderGlobalStep)) {
            toReturn = toReturn != null && (toReturn && defaultValue);
            break;
        }
        currentStep = currentStep.getNextStep();
    }
    return Boolean.TRUE.equals(toReturn);
}
 
Example #13
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public static void extractCount(Step<?, ?> newStep,
                                Traversal.Admin<?, ?> traversal) {
    Step<?, ?> step = newStep;
    do {
        step = step.getNextStep();
        if (step instanceof CountGlobalStep) {
            QueryHolder holder = (QueryHolder) newStep;
            holder.setCount();
        }
    } while (step instanceof CountGlobalStep ||
             step instanceof FilterStep ||
             step instanceof IdentityStep ||
             step instanceof NoOpBarrierStep);
}
 
Example #14
Source File: RepeatUnrollStrategy.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    if (TraversalHelper.onGraphComputer(traversal))
        return;

    for (int i = 0; i < traversal.getSteps().size(); i++) {
        if (traversal.getSteps().get(i) instanceof RepeatStep) {
            final RepeatStep<?> repeatStep = (RepeatStep) traversal.getSteps().get(i);
            if (null == repeatStep.getEmitTraversal() && null != repeatStep.getRepeatTraversal() &&
                    repeatStep.getUntilTraversal() instanceof LoopTraversal && ((LoopTraversal) repeatStep.getUntilTraversal()).getMaxLoops() > 0 &&
                    !TraversalHelper.hasStepOfAssignableClassRecursively(Scope.global, DedupGlobalStep.class, repeatStep.getRepeatTraversal()) &&
                    !TraversalHelper.hasStepOfAssignableClassRecursively(INVALIDATING_STEPS, repeatStep.getRepeatTraversal())) {
                final Traversal.Admin<?, ?> repeatTraversal = repeatStep.getGlobalChildren().get(0);
                repeatTraversal.removeStep(repeatTraversal.getSteps().size() - 1); // removes the RepeatEndStep
                TraversalHelper.applySingleLevelStrategies(traversal, repeatTraversal, RepeatUnrollStrategy.class);
                final int repeatLength = repeatTraversal.getSteps().size();
                int insertIndex = i;
                final int loops = (int) ((LoopTraversal) repeatStep.getUntilTraversal()).getMaxLoops();
                for (int j = 0; j < loops; j++) {
                    TraversalHelper.insertTraversal(insertIndex, repeatTraversal.clone(), traversal);
                    insertIndex = insertIndex + repeatLength;
                    if ((j != (loops - 1) || !(traversal.getSteps().get(insertIndex).getNextStep() instanceof Barrier)) // only add a final NoOpBarrier is subsequent step is not a barrier
                        && !(traversal.getSteps().get(insertIndex) instanceof NoOpBarrierStep) // Don't add a barrier if this step is a barrier (prevents nested repeat adding the barrier multiple times)
                       ) {
                        traversal.addStep(++insertIndex, new NoOpBarrierStep<>(traversal, MAX_BARRIER_SIZE));
                    }
                }
                // label last step if repeat() was labeled
                if (!repeatStep.getLabels().isEmpty())
                    TraversalHelper.copyLabels(repeatStep, traversal.getSteps().get(insertIndex), false);
                traversal.removeStep(i); // remove the RepeatStep
            }
        }
    }
}
 
Example #15
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public static void extractRange(Step<?, ?> newStep,
                                Traversal.Admin<?, ?> traversal,
                                boolean extractOnlyLimit) {
    QueryHolder holder = (QueryHolder) newStep;
    Step<?, ?> step = newStep;
    do {
        step = step.getNextStep();
        if (step instanceof RangeGlobalStep) {
            @SuppressWarnings("unchecked")
            RangeGlobalStep<Object> range = (RangeGlobalStep<Object>) step;
            /*
             * NOTE: keep the step to limit results after query from DB
             * due to `limit`(in DB) may not be implemented accurately.
             * but the backend driver should ensure `offset` accurately.
             */
            // TraversalHelper.copyLabels(step, newStep, false);
            // traversal.removeStep(step);
            if (extractOnlyLimit) {
                // May need to retain offset for multiple sub-queries
                holder.setRange(0, range.getHighRange());
            } else {
                long limit = holder.setRange(range.getLowRange(),
                                             range.getHighRange());
                RangeGlobalStep<Object> newRange = new RangeGlobalStep<>(
                                                   traversal, 0, limit);
                TraversalHelper.replaceStep(range, newRange, traversal);
            }
        }
    } while (step instanceof RangeGlobalStep ||
             step instanceof IdentityStep ||
             step instanceof NoOpBarrierStep);
}
 
Example #16
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 5 votes vote down vote up
public static void extractHasContainer(HugeVertexStep<?> newStep,
                                       Traversal.Admin<?, ?> traversal) {
    Step<?, ?> step = newStep;
    do {
        if (step instanceof HasStep) {
            HasContainerHolder holder = (HasContainerHolder) step;
            for (HasContainer has : holder.getHasContainers()) {
                newStep.addHasContainer(has);
            }
            TraversalHelper.copyLabels(step, step.getPreviousStep(), false);
            traversal.removeStep(step);
        }
        step = step.getNextStep();
    } while (step instanceof HasStep || step instanceof NoOpBarrierStep);
}
 
Example #17
Source File: HugeCountStepStrategy.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void apply(Traversal.Admin<?, ?> traversal) {
    TraversalUtil.convAllHasSteps(traversal);

    // Extract CountGlobalStep
    List<CountGlobalStep> steps = TraversalHelper.getStepsOfClass(
                                  CountGlobalStep.class, traversal);
    if (steps.isEmpty()) {
        return;
    }

    // Find HugeGraphStep before count()
    CountGlobalStep<?> originStep = steps.get(0);
    List<Step<?, ?>> originSteps = new ArrayList<>();
    HugeGraphStep<?, ? extends Element> graphStep = null;
    Step<?, ?> step = originStep;
    do {
        if (!(step instanceof CountGlobalStep ||
              step instanceof GraphStep ||
              step instanceof IdentityStep ||
              step instanceof NoOpBarrierStep ||
              step instanceof CollectingBarrierStep) ||
             (step instanceof TraversalParent &&
              TraversalHelper.anyStepRecursively(s -> {
                  return s instanceof SideEffectStep ||
                         s instanceof AggregateStep;
              }, (TraversalParent) step))) {
            return;
        }
        originSteps.add(step);
        if (step instanceof HugeGraphStep) {
            graphStep = (HugeGraphStep<?, ? extends Element>) step;
            break;
        }
        step = step.getPreviousStep();
    } while (step != null);

    if (graphStep == null) {
        return;
    }

    // Replace with HugeCountStep
    graphStep.queryInfo().aggregate(AggregateFunc.COUNT, null);
    HugeCountStep<?> countStep = new HugeCountStep<>(traversal, graphStep);
    for (Step<?, ?> origin : originSteps) {
        traversal.removeStep(origin);
    }
    traversal.addStep(0, countStep);
}
 
Example #18
Source File: TraversalUtil.java    From hugegraph with Apache License 2.0 4 votes vote down vote up
public static void extractAggregateFunc(Step<?, ?> newStep,
                                        Traversal.Admin<?, ?> traversal) {
    PropertiesStep<?> propertiesStep = null;
    Step<?, ?> step = newStep;
    do {
        step = step.getNextStep();
        if (step instanceof PropertiesStep) {
            @SuppressWarnings("resource")
            PropertiesStep<?> propStep = (PropertiesStep<?>) step;
            if (propStep.getReturnType() == PropertyType.VALUE &&
                propStep.getPropertyKeys().length == 1) {
                propertiesStep = propStep;
            }
        } else if (propertiesStep != null &&
                   step instanceof ReducingBarrierStep) {
            AggregateFunc aggregateFunc;
            if (step instanceof CountGlobalStep) {
                aggregateFunc = AggregateFunc.COUNT;
            } else if (step instanceof MaxGlobalStep) {
                aggregateFunc = AggregateFunc.MAX;
            } else if (step instanceof MinGlobalStep) {
                aggregateFunc = AggregateFunc.MIN;
            } else if (step instanceof MeanGlobalStep) {
                aggregateFunc = AggregateFunc.AVG;
            } else if (step instanceof SumGlobalStep) {
                aggregateFunc = AggregateFunc.SUM;
            } else {
                aggregateFunc = null;
            }

            if (aggregateFunc != null) {
                QueryHolder holder = (QueryHolder) newStep;
                holder.setAggregate(aggregateFunc,
                                    propertiesStep.getPropertyKeys()[0]);
                traversal.removeStep(step);
                traversal.removeStep(propertiesStep);
            }
        }
    } while (step instanceof FilterStep ||
             step instanceof PropertiesStep ||
             step instanceof IdentityStep ||
             step instanceof NoOpBarrierStep);
}
 
Example #19
Source File: LazyBarrierStrategy.java    From tinkerpop with Apache License 2.0 4 votes vote down vote up
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
    // drop() is a problem for bulked edge/meta properties because of Property equality changes in TINKERPOP-2318
    // which made it so that a Property is equal if the key/value is equal. as a result, they bulk together which
    // is fine for almost all cases except when you wish to drop the property.
    if (TraversalHelper.onGraphComputer(traversal) ||
            traversal.getTraverserRequirements().contains(TraverserRequirement.PATH) ||
            TraversalHelper.hasStepOfAssignableClass(DropStep.class, traversal))
        return;

    boolean foundFlatMap = false;
    boolean labeledPath = false;
    for (int i = 0; i < traversal.getSteps().size(); i++) {
        final Step<?, ?> step = traversal.getSteps().get(i);

        if (step instanceof PathProcessor) {
            final Set<String> keepLabels = ((PathProcessor) step).getKeepLabels();
            if (null != keepLabels && keepLabels.isEmpty()) // if no more path data, then start barrier'ing again
                labeledPath = false;
        }
        if (step instanceof FlatMapStep &&
                !(step instanceof VertexStep && ((VertexStep) step).returnsEdge()) ||
                (step instanceof GraphStep &&
                        (i > 0 || ((GraphStep) step).getIds().length >= BIG_START_SIZE ||
                                (((GraphStep) step).getIds().length == 0 && !(step.getNextStep() instanceof HasStep))))) {

            // NoneStep, EmptyStep signify the end of the traversal where no barriers are really going to be
            // helpful after that. ProfileSideEffectStep means the traversal had profile() called on it and if
            // we don't account for that a barrier will inject at the end of the traversal where it wouldn't
            // be otherwise. LazyBarrierStrategy executes before the finalization strategy of ProfileStrategy
            // so additionally injected ProfileSideEffectStep instances should not have effect here.
            if (foundFlatMap && !labeledPath &&
                    !(step.getNextStep() instanceof Barrier) &&
                    !(step.getNextStep() instanceof NoneStep) &&
                    !(step.getNextStep() instanceof EmptyStep) &&
                    !(step.getNextStep() instanceof ProfileSideEffectStep)) {
                final Step noOpBarrierStep = new NoOpBarrierStep<>(traversal, MAX_BARRIER_SIZE);
                TraversalHelper.copyLabels(step, noOpBarrierStep, true);
                TraversalHelper.insertAfterStep(noOpBarrierStep, step, traversal);
            } else
                foundFlatMap = true;
        }
        if (!step.getLabels().isEmpty())
            labeledPath = true;

    }
}
 
Example #20
Source File: GraphTraversal.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Turns the lazy traversal pipeline into a bulk-synchronous pipeline which basically iterates that traversal to
 * the size of the barrier. In this case, it iterates the entire thing as the default barrier size is set to
 * {@code Integer.MAX_VALUE}.
 *
 * @return the traversal with an appended {@link NoOpBarrierStep}
 * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#barrier-step" target="_blank">Reference Documentation - Barrier Step</a>
 * @since 3.0.0-incubating
 */
public default GraphTraversal<S, E> barrier() {
    this.asAdmin().getBytecode().addStep(Symbols.barrier);
    return this.asAdmin().addStep(new NoOpBarrierStep<>(this.asAdmin(), Integer.MAX_VALUE));
}
 
Example #21
Source File: GraphTraversal.java    From tinkerpop with Apache License 2.0 2 votes vote down vote up
/**
 * Turns the lazy traversal pipeline into a bulk-synchronous pipeline which basically iterates that traversal to
 * the size of the barrier.
 *
 * @param maxBarrierSize the size of the barrier
 * @return the traversal with an appended {@link NoOpBarrierStep}
 * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#barrier-step" target="_blank">Reference Documentation - Barrier Step</a>
 * @since 3.0.0-incubating
 */
public default GraphTraversal<S, E> barrier(final int maxBarrierSize) {
    this.asAdmin().getBytecode().addStep(Symbols.barrier, maxBarrierSize);
    return this.asAdmin().addStep(new NoOpBarrierStep<>(this.asAdmin(), maxBarrierSize));
}