private static boolean insertElementId(final Step<?, ?> barrier) { if (!(barrier instanceof Barrier)) return false; else if (!endsWithElement(barrier.getPreviousStep())) return false; else if (barrier instanceof CountGlobalStep) return true; else if (barrier instanceof DedupGlobalStep && ((DedupGlobalStep) barrier).getScopeKeys().isEmpty() && ((DedupGlobalStep) barrier).getLocalChildren().isEmpty() && barrier.getNextStep() instanceof CountGlobalStep) return true; else return false; }
@Override public MemoryComputeKey<Map<Object, Traverser.Admin<S>>> getMemoryComputeKey() { return MemoryComputeKey.of(this.getId(), (BinaryOperator) Operator.addAll, false, true); }
@Override protected boolean filter(final Traverser.Admin<S> traverser) { if (this.onGraphComputer && !this.executingAtMaster) return true; traverser.setBulk(1L); if (null == this.dedupLabels) { return this.duplicateSet.add(TraversalUtil.applyNullable(traverser, this.dedupTraversal)); } else { final List<Object> objects = new ArrayList<>(this.dedupLabels.size()); this.dedupLabels.forEach(label -> objects.add(TraversalUtil.applyNullable((S) this.getScopeValue(Pop.last, label, traverser), this.dedupTraversal))); return this.duplicateSet.add(objects); } }
if ((traversal.getParent() instanceof ConnectiveStep) || TraversalHelper.hasStepOfClass(MatchStep.MatchStartStep.class, traversal)) { propertyFetcher.fetchAllKeys(); } else if (dedupGlobalStep.getLocalChildren().size() > 0) if (dedupGlobalStep.getLocalChildren().get(0) instanceof ElementValueTraversal) { String propertyKey = ((ElementValueTraversal) dedupGlobalStep.getLocalChildren().get(0)).getPropertyKey(); handlePropertiesSteps(new String[]{propertyKey}, propertyFetcher);
/** * Remove all duplicates in the traversal stream up to this point. * * @param dedupLabels if labels are provided, then the scoped object's labels determine de-duplication. No labels implies current object. * @return the traversal with an appended {@link DedupGlobalStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#dedup-step" target="_blank">Reference Documentation - Dedup Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> dedup(final String... dedupLabels) { this.asAdmin().getBytecode().addStep(Symbols.dedup, dedupLabels); return this.asAdmin().addStep(new DedupGlobalStep<>(this.asAdmin(), dedupLabels)); }
@Override public void modulateBy(final Traversal.Admin<?, ?> dedupTraversal) { this.dedupTraversal = this.integrateChild(dedupTraversal); }
@Override public Set<TraverserRequirement> getRequirements() { return this.dedupLabels == null ? this.getSelfAndChildRequirements(TraverserRequirement.BULK) : this.getSelfAndChildRequirements(TraverserRequirement.LABELED_PATH, TraverserRequirement.BULK); }
/** * Remove all duplicates in the traversal stream up to this point. * * @param scope whether the deduplication is on the stream (global) or the current object (local). * @param dedupLabels if labels are provided, then the scope labels determine de-duplication. No labels implies current object. * @return the traversal with an appended {@link DedupGlobalStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#dedup-step" target="_blank">Reference Documentation - Dedup Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> dedup(final Scope scope, final String... dedupLabels) { this.asAdmin().getBytecode().addStep(Symbols.dedup, scope, dedupLabels); return this.asAdmin().addStep(scope.equals(Scope.global) ? new DedupGlobalStep<>(this.asAdmin(), dedupLabels) : new DedupLocalStep(this.asAdmin())); }
@Override public void setTraversal(final Traversal.Admin<?, ?> parentTraversal) { super.setTraversal(parentTraversal); this.integrateChild(this.dedupTraversal); }
@Override public Set<TraverserRequirement> getRequirements() { return this.dedupLabels == null ? this.getSelfAndChildRequirements(TraverserRequirement.BULK) : this.getSelfAndChildRequirements(TraverserRequirement.LABELED_PATH, TraverserRequirement.BULK); }
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (!TraversalHelper.hasStepOfClass(MatchStep.class, traversal)) return; TraversalHelper.getStepsOfClass(MatchStep.class, traversal).forEach(matchStep -> { // match().select().where() --> match(where()).select() // match().select().dedup() --> match(dedup()).select() Step<?, ?> nextStep = matchStep.getNextStep(); while (nextStep instanceof WherePredicateStep || nextStep instanceof WhereTraversalStep || (nextStep instanceof DedupGlobalStep && !((DedupGlobalStep) nextStep).getScopeKeys().isEmpty() && ((DedupGlobalStep) nextStep).getLocalChildren().isEmpty()) || (nextStep instanceof SelectStep && ((SelectStep) nextStep).getLocalChildren().isEmpty()) || (nextStep instanceof SelectOneStep && ((SelectOneStep) nextStep).getLocalChildren().isEmpty())) { if (nextStep instanceof WherePredicateStep || nextStep instanceof WhereTraversalStep) { traversal.removeStep(nextStep); matchStep.addGlobalChild(traversal instanceof GraphTraversal ? new DefaultGraphTraversal<>().addStep(nextStep) : new DefaultTraversal<>().addStep(nextStep)); nextStep = matchStep.getNextStep(); } else if (nextStep instanceof DedupGlobalStep && !((DedupGlobalStep) nextStep).getScopeKeys().isEmpty() && ((DedupGlobalStep) nextStep).getLocalChildren().isEmpty() && !TraversalHelper.onGraphComputer(traversal)) { traversal.removeStep(nextStep); matchStep.setDedupLabels(((DedupGlobalStep<?>) nextStep).getScopeKeys()); nextStep = matchStep.getNextStep(); } else if (nextStep.getLabels().isEmpty()) { nextStep = nextStep.getNextStep(); } else break; } }); }
/** * Remove all duplicates in the traversal stream up to this point. * * @param dedupLabels if labels are provided, then the scoped object's labels determine de-duplication. No labels implies current object. * @return the traversal with an appended {@link DedupGlobalStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#dedup-step" target="_blank">Reference Documentation - Dedup Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> dedup(final String... dedupLabels) { this.asAdmin().getBytecode().addStep(Symbols.dedup, dedupLabels); return this.asAdmin().addStep(new DedupGlobalStep<>(this.asAdmin(), dedupLabels)); }
@Override public void modulateBy(final Traversal.Admin<?, ?> dedupTraversal) { this.dedupTraversal = this.integrateChild(dedupTraversal); }
@Override public Map<Object, Traverser.Admin<S>> nextBarrier() throws NoSuchElementException { final Map<Object, Traverser.Admin<S>> map = null != this.barrier ? this.barrier : new HashMap<>(); while (this.starts.hasNext()) { final Traverser.Admin<S> traverser = this.starts.next(); final Object object; if (null != this.dedupLabels) { object = new ArrayList<>(this.dedupLabels.size()); for (final String label : this.dedupLabels) { ((List) object).add(TraversalUtil.applyNullable((S) this.getScopeValue(Pop.last, label, traverser), this.dedupTraversal)); } } else { object = TraversalUtil.applyNullable(traverser, this.dedupTraversal); } if (!map.containsKey(object)) { traverser.setBulk(1L); // traverser.detach(); traverser.set(DetachedFactory.detach(traverser.get(), true)); // TODO: detect required detachment accordingly map.put(object, traverser); } } this.barrier = null; this.barrierIterator = null; if (map.isEmpty()) throw FastNoSuchElementException.instance(); else return map; }
@Override public MemoryComputeKey<Map<Object, Traverser.Admin<S>>> getMemoryComputeKey() { return MemoryComputeKey.of(this.getId(), (BinaryOperator) Operator.addAll, false, true); }
private static boolean insertElementId(final Step<?, ?> barrier) { if (!(barrier instanceof Barrier)) return false; else if (!endsWithElement(barrier.getPreviousStep())) return false; else if (barrier instanceof CountGlobalStep) return true; else if (barrier instanceof DedupGlobalStep && ((DedupGlobalStep) barrier).getScopeKeys().isEmpty() && ((DedupGlobalStep) barrier).getLocalChildren().isEmpty() && barrier.getNextStep() instanceof CountGlobalStep) return true; else return false; }
/** * Remove all duplicates in the traversal stream up to this point. * * @param scope whether the deduplication is on the stream (global) or the current object (local). * @param dedupLabels if labels are provided, then the scope labels determine de-duplication. No labels implies current object. * @return the traversal with an appended {@link DedupGlobalStep}. * @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#dedup-step" target="_blank">Reference Documentation - Dedup Step</a> * @since 3.0.0-incubating */ public default GraphTraversal<S, E> dedup(final Scope scope, final String... dedupLabels) { this.asAdmin().getBytecode().addStep(Symbols.dedup, scope, dedupLabels); return this.asAdmin().addStep(scope.equals(Scope.global) ? new DedupGlobalStep<>(this.asAdmin(), dedupLabels) : new DedupLocalStep(this.asAdmin())); }
@Override public void setTraversal(final Traversal.Admin<?, ?> parentTraversal) { super.setTraversal(parentTraversal); this.integrateChild(this.dedupTraversal); }
@Override protected boolean filter(final Traverser.Admin<S> traverser) { if (this.onGraphComputer && !this.executingAtMaster) return true; traverser.setBulk(1L); if (null == this.dedupLabels) { return this.duplicateSet.add(TraversalUtil.applyNullable(traverser, this.dedupTraversal)); } else { final List<Object> objects = new ArrayList<>(this.dedupLabels.size()); this.dedupLabels.forEach(label -> objects.add(TraversalUtil.applyNullable((S) this.getScopeValue(Pop.last, label, traverser), this.dedupTraversal))); return this.duplicateSet.add(objects); } }
@Override public void apply(final Traversal.Admin<?, ?> traversal) { if (!TraversalHelper.hasStepOfClass(MatchStep.class, traversal)) return; TraversalHelper.getStepsOfClass(MatchStep.class, traversal).forEach(matchStep -> { // match().select().where() --> match(where()).select() // match().select().dedup() --> match(dedup()).select() Step<?, ?> nextStep = matchStep.getNextStep(); while (nextStep instanceof WherePredicateStep || nextStep instanceof WhereTraversalStep || (nextStep instanceof DedupGlobalStep && !((DedupGlobalStep) nextStep).getScopeKeys().isEmpty() && ((DedupGlobalStep) nextStep).getLocalChildren().isEmpty()) || (nextStep instanceof SelectStep && ((SelectStep) nextStep).getLocalChildren().isEmpty()) || (nextStep instanceof SelectOneStep && ((SelectOneStep) nextStep).getLocalChildren().isEmpty())) { if (nextStep instanceof WherePredicateStep || nextStep instanceof WhereTraversalStep) { traversal.removeStep(nextStep); matchStep.addGlobalChild(traversal instanceof GraphTraversal ? new DefaultGraphTraversal<>().addStep(nextStep) : new DefaultTraversal<>().addStep(nextStep)); nextStep = matchStep.getNextStep(); } else if (nextStep instanceof DedupGlobalStep && !((DedupGlobalStep) nextStep).getScopeKeys().isEmpty() && ((DedupGlobalStep) nextStep).getLocalChildren().isEmpty() && !TraversalHelper.onGraphComputer(traversal)) { traversal.removeStep(nextStep); matchStep.setDedupLabels(((DedupGlobalStep<?>) nextStep).getScopeKeys()); nextStep = matchStep.getNextStep(); } else if (nextStep.getLabels().isEmpty()) { nextStep = nextStep.getNextStep(); } else break; } }); }