[tinkerpop] 01/02: TINKERPOP-1084 Allow predicates to be used as options in BranchSteps.
This is an automated email from the ASF dual-hosted git repository. dkuppitz pushed a commit to branch TINKERPOP-1084 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git commit d9701276194f8496410ba2b8f95ee8876beb1ca2 Author: Daniel Kuppitz AuthorDate: Mon Jun 10 12:45:16 2019 -0700 TINKERPOP-1084 Allow predicates to be used as options in BranchSteps. --- CHANGELOG.asciidoc | 1 + .../process/traversal/step/branch/BranchStep.java | 102 - .../process/traversal/step/ComplexTest.java| 58 +--- .../tinkergraph/structure/TinkerGraphPlayTest.java | 22 +++-- 4 files changed, 141 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 0b7d75e..320930e 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -31,6 +31,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima * Fixed multiple iterator leaks in query processor. * Fixed bug in `MatchStep` where the correct was not properly determined. * Fixed bug where client/server exception mismatch when server throw StackOverflowError +* Allow predicates to be used as options in BranchSteps. [[release-3-3-7]] === TinkerPop 3.3.7 (Release Date: May 28, 2019) diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/BranchStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/BranchStep.java index e35d51e..efc43cc 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/BranchStep.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/BranchStep.java @@ -38,18 +38,23 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.function.Predicate; import java.util.stream.Collectors; /** * @author Marko A. Rodriguez (http://markorodriguez.com) + * @author Daniel Kuppitz (http://gremlin.guru) */ public class BranchStep extends ComputerAwareStep implements TraversalOptionParent { protected Traversal.Admin branchTraversal; protected Map>> traversalOptions = new HashMap<>(); + private boolean first = true; -private boolean hasBarrier = false; +private boolean hasBarrier; +private boolean hasPredicateOptions; public BranchStep(final Traversal.Admin traversal) { super(traversal); @@ -61,7 +66,8 @@ public class BranchStep extends ComputerAwareStep implements Trav @Override public void addGlobalChildOption(final M pickToken, final Traversal.Admin traversalOption) { -final Object pickTokenKey = PickTokenKey.make(pickToken); +final Object pickTokenKey = makePickTokenKey(pickToken); +this.hasPredicateOptions |= pickTokenKey instanceof PredicateOption; if (this.traversalOptions.containsKey(pickTokenKey)) this.traversalOptions.get(pickTokenKey).add(traversalOption); else @@ -138,14 +144,13 @@ public class BranchStep extends ComputerAwareStep implements Trav private void applyCurrentTraverser(final Traverser.Admin start) { // first get the value of the choice based on the current traverser and use that to select the right traversal // option to which that traverser should be routed -final Object choice = PickTokenKey.make(TraversalUtil.apply(start, this.branchTraversal)); -final List> branch = this.traversalOptions.containsKey(choice) ? -this.traversalOptions.get(choice) : this.traversalOptions.get(Pick.none); +final Object choice = makePickTokenKey(TraversalUtil.apply(start, this.branchTraversal)); +final List> branches = pickBranches(choice); // if a branch is identified, then split the traverser and add it to the start of the option so that when // that option is iterated (in the calling method) that value can be applied. -if (null != branch) -branch.forEach(traversal -> traversal.addStart(start.split())); +if (null != branches) +branches.forEach(traversal -> traversal.addStart(start.split())); if (choice != Pick.any) { final List> anyBranch = this.traversalOptions.get(Pick.any); @@ -158,10 +163,10 @@ public class BranchStep extends ComputerAwareStep implements Trav protected Iterator> computerAlgorithm() { final List> ends = new ArrayList<>(); final Traverser.Admin start = this.starts.next(); -final Object choice = PickTokenKey.make(TraversalUtil.apply(start, this.branchTraversal)); -final List> branch = this.traversalOptions.containsKey(choice) ? this.traversalOptions.get(choice) : this.traversalOptions.get(Pick.none); -if (null != branch) { -branch.forEach(traversal -> { +final
[tinkerpop] 01/02: TINKERPOP-1084 Allow predicates to be used as options in BranchSteps.
This is an automated email from the ASF dual-hosted git repository. dkuppitz pushed a commit to branch TINKERPOP-1084 in repository https://gitbox.apache.org/repos/asf/tinkerpop.git commit 2bc081daf86548e245d2c918193581fb4c131411 Author: Daniel Kuppitz AuthorDate: Mon Jun 10 12:45:16 2019 -0700 TINKERPOP-1084 Allow predicates to be used as options in BranchSteps. --- CHANGELOG.asciidoc | 1 + .../process/traversal/step/branch/BranchStep.java | 102 - .../process/traversal/step/ComplexTest.java| 58 +--- .../tinkergraph/structure/TinkerGraphPlayTest.java | 22 +++-- 4 files changed, 141 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 03ba330..8b2cd62 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -30,6 +30,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima * Added test infrastructure to check for storage iterator leak. * Fixed multiple iterator leaks in query processor. * Fixed bug in `MatchStep` where the correct was not properly determined. +* Allow predicates to be used as options in BranchSteps. [[release-3-3-7]] === TinkerPop 3.3.7 (Release Date: May 28, 2019) diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/BranchStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/BranchStep.java index e35d51e..efc43cc 100644 --- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/BranchStep.java +++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/BranchStep.java @@ -38,18 +38,23 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; +import java.util.function.Predicate; import java.util.stream.Collectors; /** * @author Marko A. Rodriguez (http://markorodriguez.com) + * @author Daniel Kuppitz (http://gremlin.guru) */ public class BranchStep extends ComputerAwareStep implements TraversalOptionParent { protected Traversal.Admin branchTraversal; protected Map>> traversalOptions = new HashMap<>(); + private boolean first = true; -private boolean hasBarrier = false; +private boolean hasBarrier; +private boolean hasPredicateOptions; public BranchStep(final Traversal.Admin traversal) { super(traversal); @@ -61,7 +66,8 @@ public class BranchStep extends ComputerAwareStep implements Trav @Override public void addGlobalChildOption(final M pickToken, final Traversal.Admin traversalOption) { -final Object pickTokenKey = PickTokenKey.make(pickToken); +final Object pickTokenKey = makePickTokenKey(pickToken); +this.hasPredicateOptions |= pickTokenKey instanceof PredicateOption; if (this.traversalOptions.containsKey(pickTokenKey)) this.traversalOptions.get(pickTokenKey).add(traversalOption); else @@ -138,14 +144,13 @@ public class BranchStep extends ComputerAwareStep implements Trav private void applyCurrentTraverser(final Traverser.Admin start) { // first get the value of the choice based on the current traverser and use that to select the right traversal // option to which that traverser should be routed -final Object choice = PickTokenKey.make(TraversalUtil.apply(start, this.branchTraversal)); -final List> branch = this.traversalOptions.containsKey(choice) ? -this.traversalOptions.get(choice) : this.traversalOptions.get(Pick.none); +final Object choice = makePickTokenKey(TraversalUtil.apply(start, this.branchTraversal)); +final List> branches = pickBranches(choice); // if a branch is identified, then split the traverser and add it to the start of the option so that when // that option is iterated (in the calling method) that value can be applied. -if (null != branch) -branch.forEach(traversal -> traversal.addStart(start.split())); +if (null != branches) +branches.forEach(traversal -> traversal.addStart(start.split())); if (choice != Pick.any) { final List> anyBranch = this.traversalOptions.get(Pick.any); @@ -158,10 +163,10 @@ public class BranchStep extends ComputerAwareStep implements Trav protected Iterator> computerAlgorithm() { final List> ends = new ArrayList<>(); final Traverser.Admin start = this.starts.next(); -final Object choice = PickTokenKey.make(TraversalUtil.apply(start, this.branchTraversal)); -final List> branch = this.traversalOptions.containsKey(choice) ? this.traversalOptions.get(choice) : this.traversalOptions.get(Pick.none); -if (null != branch) { -branch.forEach(traversal -> { +final Object choice = makePickT