@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; } }); }
@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; } }); }