org.apache.tinkerpop.gremlin.process.traversal.step.util.CollectingBarrierStep Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.step.util.CollectingBarrierStep.
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: TinkerGraphCountStrategy.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@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 #2
Source File: TinkerGraphCountStrategy.java From tinkerpop with Apache License 2.0 | 6 votes |
@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 #3
Source File: HugeCountStepStrategy.java From hugegraph with Apache License 2.0 | 4 votes |
@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); }