You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2016/11/09 05:06:14 UTC
[1/4] tinkerpop git commit: Fixed LazyBarrierStrategy and
PathRetractionStrategy (still wip)
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1529-variant2 [created] 5a8be6b9f
Fixed LazyBarrierStrategy and PathRetractionStrategy (still wip)
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/1409f631
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/1409f631
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/1409f631
Branch: refs/heads/TINKERPOP-1529-variant2
Commit: 1409f631fda734a2bf46b37bc13d261d7e812880
Parents: 0a74d78
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Mon Oct 31 12:33:09 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Tue Nov 8 00:42:51 2016 +0100
----------------------------------------------------------------------
.../optimization/LazyBarrierStrategy.java | 25 ++++---
.../optimization/PathRetractionStrategy.java | 13 ++--
.../traversal/util/SideEffectHelper.java | 74 ++++++++++++++++++++
.../traversal/step/sideEffect/StoreTest.java | 25 ++++---
4 files changed, 113 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1409f631/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java
index 96da26f..db8b17c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java
@@ -33,6 +33,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.process.traversal.util.SideEffectHelper;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import java.util.Arrays;
@@ -44,7 +45,7 @@ import java.util.Set;
*/
public final class LazyBarrierStrategy extends AbstractTraversalStrategy<TraversalStrategy.OptimizationStrategy> implements TraversalStrategy.OptimizationStrategy {
- private final boolean IS_TESTING = Boolean.valueOf(System.getProperty("is.testing", "false"));
+ protected static final int MAX_BARRIER_SIZE = 2500;
private static final LazyBarrierStrategy INSTANCE = new LazyBarrierStrategy();
private static final Set<Class<? extends OptimizationStrategy>> PRIORS = new HashSet<>(Arrays.asList(
RangeByIsCountStrategy.class,
@@ -56,11 +57,15 @@ public final class LazyBarrierStrategy extends AbstractTraversalStrategy<Travers
MatchPredicateStrategy.class));
private static final int BIG_START_SIZE = 5;
- protected static final int MAX_BARRIER_SIZE = 2500;
+ private final boolean IS_TESTING = Boolean.valueOf(System.getProperty("is.testing", "false"));
private LazyBarrierStrategy() {
}
+ public static LazyBarrierStrategy instance() {
+ return INSTANCE;
+ }
+
@Override
public void apply(final Traversal.Admin<?, ?> traversal) {
if (TraversalHelper.onGraphComputer(traversal) ||
@@ -69,12 +74,13 @@ public final class LazyBarrierStrategy extends AbstractTraversalStrategy<Travers
TraversalHelper.hasStepOfAssignableClass(ProfileSideEffectStep.class, TraversalHelper.getRootTraversal(traversal)))) // necessary cause ProfileTest analyzes counts
return;
+ final Set<String> frozenStepIds = SideEffectHelper.determineFrozenStepIds(traversal);
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) {
+ if (step instanceof PathProcessor && labeledPath) {
final Set<String> keepLabels = ((PathProcessor) step).getKeepLabels();
if (null != keepLabels && keepLabels.isEmpty()) // if no more path data, then start barrier'ing again
labeledPath = false;
@@ -84,12 +90,16 @@ public final class LazyBarrierStrategy extends AbstractTraversalStrategy<Travers
(step instanceof GraphStep &&
(i > 0 || ((GraphStep) step).getIds().length >= BIG_START_SIZE ||
(((GraphStep) step).getIds().length == 0 && !(step.getNextStep() instanceof HasStep))))) {
- if (foundFlatMap && !labeledPath &&
+ if (foundFlatMap && !labeledPath && !frozenStepIds.contains(step.getId()) &&
!(step.getNextStep() instanceof Barrier) &&
(!(step.getNextStep() instanceof EmptyStep) || step.getTraversal().getParent() instanceof EmptyStep)) {
final Step noOpBarrierStep = new NoOpBarrierStep<>(traversal, MAX_BARRIER_SIZE);
- TraversalHelper.copyLabels(step, noOpBarrierStep, true);
+ if (labeledPath = !step.getLabels().isEmpty()) {
+ TraversalHelper.copyLabels(step, noOpBarrierStep, true);
+ }
TraversalHelper.insertAfterStep(noOpBarrierStep, step, traversal);
+ i++;
+ continue;
} else
foundFlatMap = true;
}
@@ -99,13 +109,8 @@ public final class LazyBarrierStrategy extends AbstractTraversalStrategy<Travers
}
}
-
@Override
public Set<Class<? extends OptimizationStrategy>> applyPrior() {
return PRIORS;
}
-
- public static LazyBarrierStrategy instance() {
- return INSTANCE;
- }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1409f631/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
index da869b2..700fdfd 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
@@ -32,6 +32,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
import org.apache.tinkerpop.gremlin.process.traversal.util.PathUtil;
+import org.apache.tinkerpop.gremlin.process.traversal.util.SideEffectHelper;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.javatuples.Pair;
@@ -48,13 +49,11 @@ import java.util.Set;
*/
public final class PathRetractionStrategy extends AbstractTraversalStrategy<TraversalStrategy.OptimizationStrategy> implements TraversalStrategy.OptimizationStrategy {
- public static Integer MAX_BARRIER_SIZE = 2500;
-
- private static final PathRetractionStrategy INSTANCE = new PathRetractionStrategy(MAX_BARRIER_SIZE);
// these strategies do strong rewrites involving path labeling and thus, should run prior to PathRetractionStrategy
private static final Set<Class<? extends OptimizationStrategy>> PRIORS = new HashSet<>(Arrays.asList(
RepeatUnrollStrategy.class, MatchPredicateStrategy.class, PathProcessorStrategy.class));
-
+ public static Integer MAX_BARRIER_SIZE = 2500;
+ private static final PathRetractionStrategy INSTANCE = new PathRetractionStrategy(MAX_BARRIER_SIZE);
private final int standardBarrierSize;
private PathRetractionStrategy(final int standardBarrierSize) {
@@ -69,9 +68,10 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav
public void apply(final Traversal.Admin<?, ?> traversal) {
// do not apply this strategy if there are lambdas as you can't introspect to know what path information the lambdas are using
// do not apply this strategy if a PATH requirement step is being used (in the future, we can do PATH requirement lookhead to be more intelligent about its usage)
- if (TraversalHelper.anyStepRecursively(step -> step instanceof LambdaHolder || step.getRequirements().contains(TraverserRequirement.PATH), TraversalHelper.getRootTraversal(traversal)))
+ if (TraversalHelper.anyStepRecursively(step -> (step instanceof LambdaHolder || step.getRequirements().contains(TraverserRequirement.PATH)), TraversalHelper.getRootTraversal(traversal)))
return;
+ final Set<String> frozenStepIds = SideEffectHelper.determineFrozenStepIds(traversal);
final boolean onGraphComputer = TraversalHelper.onGraphComputer(traversal);
final Set<String> foundLabels = new HashSet<>();
final Set<String> keepLabels = new HashSet<>();
@@ -109,7 +109,8 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav
!(currentStep instanceof MatchStep) &&
!(currentStep instanceof Barrier) &&
!(currentStep.getNextStep() instanceof Barrier) &&
- !(currentStep.getTraversal().getParent() instanceof MatchStep))
+ !(currentStep.getTraversal().getParent() instanceof MatchStep) &&
+ !(frozenStepIds.contains(currentStep.getId())))
TraversalHelper.insertAfterStep(new NoOpBarrierStep<>(traversal, this.standardBarrierSize), currentStep, traversal);
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1409f631/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java
index d605c76..1193daf 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java
@@ -18,7 +18,23 @@
*/
package org.apache.tinkerpop.gremlin.process.traversal.util;
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
+import org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
+import org.apache.tinkerpop.gremlin.process.traversal.step.SideEffectCapable;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -44,4 +60,62 @@ public final class SideEffectHelper {
SideEffectHelper.validateSideEffectKey(key);
SideEffectHelper.validateSideEffectValue(value);
}
+
+ public static Set<String> determineFrozenStepIds(final Traversal.Admin<?, ?> traversal) {
+ final Set<String> frozenStepIds = new HashSet<>();
+ if (!TraversalHelper.onGraphComputer(traversal)) {
+ final Map<String, LinkedList<List<String>>> frozenStepIdMap = new HashMap<>();
+ processSideEffectSteps(new HashSet<>(), frozenStepIdMap, traversal);
+ for (final LinkedList<List<String>> list : frozenStepIdMap.values()) {
+ list.removeLast();
+ list.forEach(frozenStepIds::addAll);
+ }
+ }
+ return frozenStepIds;
+ }
+
+ private static void processSideEffectSteps(final Set<String> activeSideEffectKeys,
+ final Map<String, LinkedList<List<String>>> frozenStepIdMap,
+ final Traversal.Admin<?, ?> traversal) {
+ for (final Step step : traversal.getSteps()) {
+ if (step instanceof SideEffectCapable && !(step instanceof Barrier)) {
+ final String sideEffectKey = ((SideEffectCapable) step).getSideEffectKey();
+ if (!frozenStepIdMap.containsKey(sideEffectKey)) {
+ frozenStepIdMap.put(sideEffectKey, new LinkedList<>());
+ frozenStepIdMap.get(sideEffectKey).add(new ArrayList<>());
+ }
+ activeSideEffectKeys.add(sideEffectKey);
+ continue;
+ }
+ if (step instanceof Barrier) {
+ activeSideEffectKeys.clear();
+ for (final LinkedList<List<String>> list : frozenStepIdMap.values()) {
+ if (!list.getLast().isEmpty()) {
+ list.add(new ArrayList<>());
+ }
+ }
+ }
+ if (activeSideEffectKeys.isEmpty()) {
+ continue;
+ }
+ for (final String key : activeSideEffectKeys) {
+ frozenStepIdMap.get(key).getLast().add(step.getId());
+ }
+ if (step instanceof Scoping && step.getRequirements().contains(TraverserRequirement.SIDE_EFFECTS)) {
+ for (final String key : ((Scoping) step).getScopeKeys()) {
+ if (frozenStepIdMap.containsKey(key) && activeSideEffectKeys.contains(key)) {
+ frozenStepIdMap.get(key).add(new ArrayList<>());
+ }
+ }
+ } else if (step instanceof LambdaHolder) {
+ for (final LinkedList<List<String>> list : frozenStepIdMap.values()) {
+ list.add(new ArrayList<>());
+ }
+ } else if (step instanceof TraversalParent) {
+ final TraversalParent traversalParent = (TraversalParent) step;
+ traversalParent.getGlobalChildren().forEach(t -> processSideEffectSteps(activeSideEffectKeys, frozenStepIdMap, t));
+ traversalParent.getLocalChildren().forEach(t -> processSideEffectSteps(activeSideEffectKeys, frozenStepIdMap, t));
+ }
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/1409f631/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java
index 4f65b6f..fc088fd 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java
@@ -21,6 +21,8 @@ package org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
+import org.apache.tinkerpop.gremlin.process.remote.RemoteGraph;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
import org.apache.tinkerpop.gremlin.structure.T;
@@ -135,13 +137,20 @@ public abstract class StoreTest extends AbstractGremlinProcessTest {
final Traversal<Vertex, BulkSet<String>> traversal = get_g_V_order_byXidX_storeXaX_byXnameX_out_selectXaX();
printTraversalForm(traversal);
final List<BulkSet<String>> expected = new ArrayList<>(6);
- expected.addAll(Arrays.asList(
- makeBulkSet("marko"),
- makeBulkSet("marko"),
- makeBulkSet("marko"),
- makeBulkSet("marko", "vadas", "lop", "josh"),
- makeBulkSet("marko", "vadas", "lop", "josh"),
- makeBulkSet("marko", "vadas", "lop", "josh", "ripple", "peter")));
+ final boolean onGraphComputer = traversal.asAdmin().getStrategies().getStrategy(VertexProgramStrategy.class).isPresent();
+ if (onGraphComputer || graph instanceof RemoteGraph) {
+ while (expected.size() < 6) {
+ expected.add(makeBulkSet("marko", "vadas", "lop", "josh", "ripple", "peter"));
+ }
+ } else {
+ expected.addAll(Arrays.asList(
+ makeBulkSet("marko"),
+ makeBulkSet("marko"),
+ makeBulkSet("marko"),
+ makeBulkSet("marko", "vadas", "lop", "josh"),
+ makeBulkSet("marko", "vadas", "lop", "josh"),
+ makeBulkSet("marko", "vadas", "lop", "josh", "ripple", "peter")));
+ }
while (traversal.hasNext()) {
final BulkSet<String> a = traversal.next();
boolean match = false;
@@ -151,7 +160,7 @@ public abstract class StoreTest extends AbstractGremlinProcessTest {
break;
}
}
- assertTrue(match);
+ assertTrue("" + a + " should match any item of " + expected + ".", match);
}
assertTrue(expected.isEmpty());
}
[2/4] tinkerpop git commit: minor typo fix
Posted by dk...@apache.org.
minor typo fix
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/0a74d78e
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/0a74d78e
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/0a74d78e
Branch: refs/heads/TINKERPOP-1529-variant2
Commit: 0a74d78ebf9fe040c8d3354a73ef6b195b2ed401
Parents: 9223f39
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Mon Oct 31 12:32:16 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Tue Nov 8 00:42:51 2016 +0100
----------------------------------------------------------------------
docker/scripts/build.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/0a74d78e/docker/scripts/build.sh
----------------------------------------------------------------------
diff --git a/docker/scripts/build.sh b/docker/scripts/build.sh
index 2ee4dff..cc84267 100755
--- a/docker/scripts/build.sh
+++ b/docker/scripts/build.sh
@@ -39,7 +39,7 @@ function usage {
while [ ! -z "$1" ]; do
case "$1" in
- -t | --tests ) RUN_TESTS=tue; shift ;;
+ -t | --tests ) RUN_TESTS=true; shift ;;
-i | --integration-tests ) RUN_INTEGRATION_TESTS=true; shift ;;
-n | --neo4j ) INCLUDE_NEO4J=true; shift ;;
-j | --java-docs ) BUILD_JAVA_DOCS=true; shift ;;
[4/4] tinkerpop git commit: Implemented NoBarrierStrategy
Posted by dk...@apache.org.
Implemented NoBarrierStrategy
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/5a8be6b9
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/5a8be6b9
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/5a8be6b9
Branch: refs/heads/TINKERPOP-1529-variant2
Commit: 5a8be6b9f67de40a5c37d8f70be37faf36eb2bf2
Parents: 1409f63
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed Nov 9 06:05:20 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Wed Nov 9 06:05:20 2016 +0100
----------------------------------------------------------------------
.../traversal/AbstractRemoteTraversal.java | 34 ++-
.../gremlin/process/traversal/Traversal.java | 78 +++---
.../process/traversal/TraversalStrategies.java | 94 +++----
.../lambda/AbstractLambdaTraversal.java | 106 ++++----
.../optimization/LazyBarrierStrategy.java | 5 +-
.../optimization/NoBarrierStrategy.java | 127 +++++++++
.../optimization/PathRetractionStrategy.java | 4 +-
.../traversal/util/DefaultTraversal.java | 262 ++++++++++---------
.../process/traversal/util/EmptyTraversal.java | 100 +++----
.../traversal/util/SideEffectHelper.java | 74 ------
10 files changed, 497 insertions(+), 387 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/AbstractRemoteTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/AbstractRemoteTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/AbstractRemoteTraversal.java
index 0c6a7aa..18719a6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/AbstractRemoteTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/remote/traversal/AbstractRemoteTraversal.java
@@ -42,15 +42,7 @@ import java.util.Set;
*
* @author Stephen Mallette (http://stephen.genoprime.com)
*/
-public abstract class AbstractRemoteTraversal<S,E> implements RemoteTraversal<S,E> {
-
- /**
- * Note that internally {@link #nextTraverser()} is called from within a loop (specifically in
- * {@link AbstractStep#next()} that breaks properly when a {@link java.util.NoSuchElementException} is thrown. In
- * other words the "results" should be iterated to force that failure.
- */
- @Override
- public abstract Traverser.Admin<E> nextTraverser();
+public abstract class AbstractRemoteTraversal<S, E> implements RemoteTraversal<S, E> {
@Override
public Bytecode getBytecode() {
@@ -93,17 +85,22 @@ public abstract class AbstractRemoteTraversal<S,E> implements RemoteTraversal<S,
}
@Override
+ public TraversalStrategies getStrategies() {
+ throw new UnsupportedOperationException("Remote traversals do not support this method");
+ }
+
+ @Override
public void setStrategies(final TraversalStrategies strategies) {
throw new UnsupportedOperationException("Remote traversals do not support this method");
}
@Override
- public TraversalStrategies getStrategies() {
+ public <T> Optional<T> metadata(final String key) {
throw new UnsupportedOperationException("Remote traversals do not support this method");
}
@Override
- public void setParent(final TraversalParent step) {
+ public <T> void metadata(final String key, final T value) {
throw new UnsupportedOperationException("Remote traversals do not support this method");
}
@@ -113,7 +110,7 @@ public abstract class AbstractRemoteTraversal<S,E> implements RemoteTraversal<S,
}
@Override
- public Admin<S, E> clone() {
+ public void setParent(final TraversalParent step) {
throw new UnsupportedOperationException("Remote traversals do not support this method");
}
@@ -131,4 +128,17 @@ public abstract class AbstractRemoteTraversal<S,E> implements RemoteTraversal<S,
public void setGraph(final Graph graph) {
throw new UnsupportedOperationException("Remote traversals do not support this method");
}
+
+ /**
+ * Note that internally {@link #nextTraverser()} is called from within a loop (specifically in
+ * {@link AbstractStep#next()} that breaks properly when a {@link java.util.NoSuchElementException} is thrown. In
+ * other words the "results" should be iterated to force that failure.
+ */
+ @Override
+ public abstract Traverser.Admin<E> nextTraverser();
+
+ @Override
+ public Admin<S, E> clone() {
+ throw new UnsupportedOperationException("Remote traversals do not support this method");
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traversal.java
index edc18e0..7a01d3f 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Traversal.java
@@ -59,14 +59,6 @@ import java.util.stream.StreamSupport;
*/
public interface Traversal<S, E> extends Iterator<E>, Serializable, Cloneable, AutoCloseable {
- public static class Symbols {
- private Symbols() {
- // static fields only
- }
-
- public static final String profile = "profile";
- }
-
/**
* Get access to administrative methods of the traversal via its accompanying {@link Traversal.Admin}.
*
@@ -236,20 +228,6 @@ public interface Traversal<S, E> extends Iterator<E>, Serializable, Cloneable, A
// do nothing by default
}
- /**
- * A collection of {@link Exception} types associated with Traversal execution.
- */
- public static class Exceptions {
-
- public static IllegalStateException traversalIsLocked() {
- return new IllegalStateException("The traversal strategies are complete and the traversal can no longer be modulated");
- }
-
- public static IllegalStateException traversalIsNotReversible() {
- return new IllegalStateException("The traversal is not reversible as it contains steps that are not reversible");
- }
- }
-
public interface Admin<S, E> extends Traversal<S, E> {
/**
@@ -389,6 +367,13 @@ public interface Traversal<S, E> extends Iterator<E>, Serializable, Cloneable, A
}
/**
+ * Get the {@link TraversalSideEffects} associated with the traversal.
+ *
+ * @return The traversal sideEffects
+ */
+ public TraversalSideEffects getSideEffects();
+
+ /**
* Set the {@link TraversalSideEffects} of this traversal.
*
* @param sideEffects the sideEffects to set for this traversal.
@@ -396,11 +381,11 @@ public interface Traversal<S, E> extends Iterator<E>, Serializable, Cloneable, A
public void setSideEffects(final TraversalSideEffects sideEffects);
/**
- * Get the {@link TraversalSideEffects} associated with the traversal.
+ * Get the {@link TraversalStrategies} associated with this traversal.
*
- * @return The traversal sideEffects
+ * @return the strategies associated with this traversal
*/
- public TraversalSideEffects getSideEffects();
+ public TraversalStrategies getStrategies();
/**
* Set the {@link TraversalStrategies} to be used by this traversal at evaluation time.
@@ -410,19 +395,16 @@ public interface Traversal<S, E> extends Iterator<E>, Serializable, Cloneable, A
public void setStrategies(final TraversalStrategies strategies);
/**
- * Get the {@link TraversalStrategies} associated with this traversal.
+ * Get the metadata entry for the given key.
*
- * @return the strategies associated with this traversal
+ * @return the metadata entry for the given key.
*/
- public TraversalStrategies getStrategies();
+ public <T> Optional<T> metadata(final String key);
/**
- * Set the {@link org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent} {@link Step} that is the parent of this traversal.
- * Traversals can be nested and this is the means by which the traversal tree is connected.
- *
- * @param step the traversal holder parent step
+ * Set the metadata entry for the given key.
*/
- public void setParent(final TraversalParent step);
+ public <T> void metadata(final String key, final T value);
/**
* Get the {@link org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent} {@link Step} that is the parent of this traversal.
@@ -433,6 +415,14 @@ public interface Traversal<S, E> extends Iterator<E>, Serializable, Cloneable, A
public TraversalParent getParent();
/**
+ * Set the {@link org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent} {@link Step} that is the parent of this traversal.
+ * Traversals can be nested and this is the means by which the traversal tree is connected.
+ *
+ * @param step the traversal holder parent step
+ */
+ public void setParent(final TraversalParent step);
+
+ /**
* Cloning is used to duplicate the traversal typically in OLAP environments.
*
* @return The cloned traversal
@@ -471,4 +461,26 @@ public interface Traversal<S, E> extends Iterator<E>, Serializable, Cloneable, A
}
+ public static class Symbols {
+ public static final String profile = "profile";
+
+ private Symbols() {
+ // static fields only
+ }
+ }
+
+ /**
+ * A collection of {@link Exception} types associated with Traversal execution.
+ */
+ public static class Exceptions {
+
+ public static IllegalStateException traversalIsLocked() {
+ return new IllegalStateException("The traversal strategies are complete and the traversal can no longer be modulated");
+ }
+
+ public static IllegalStateException traversalIsNotReversible() {
+ return new IllegalStateException("The traversal is not reversible as it contains steps that are not reversible");
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
index 015df70..0951045 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategies.java
@@ -28,6 +28,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.Inci
import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.InlineFilterStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.LazyBarrierStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.MatchPredicateStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.NoBarrierStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.OrderLimitStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.PathProcessorStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.PathRetractionStrategy;
@@ -64,52 +65,6 @@ public interface TraversalStrategies extends Serializable, Cloneable {
static List<Class<? extends TraversalStrategy>> STRATEGY_CATEGORIES = Collections.unmodifiableList(Arrays.asList(TraversalStrategy.DecorationStrategy.class, TraversalStrategy.OptimizationStrategy.class, TraversalStrategy.ProviderOptimizationStrategy.class, TraversalStrategy.FinalizationStrategy.class, TraversalStrategy.VerificationStrategy.class));
/**
- * Return all the {@link TraversalStrategy} singleton instances associated with this {@link TraversalStrategies}.
- */
- public List<TraversalStrategy<?>> toList();
-
- /**
- * Return the {@link TraversalStrategy} instance associated with the provided class.
- *
- * @param traversalStrategyClass the class of the strategy to get
- * @param <T> the strategy class type
- * @return an optional containing the strategy instance or not
- */
- public default <T extends TraversalStrategy> Optional<T> getStrategy(final Class<T> traversalStrategyClass) {
- return (Optional) toList().stream().filter(s -> traversalStrategyClass.isAssignableFrom(s.getClass())).findAny();
- }
-
- /**
- * Apply all the {@link TraversalStrategy} optimizers to the {@link Traversal} for the stated {@link TraversalEngine}.
- * This method must ensure that the strategies are sorted prior to application.
- *
- * @param traversal the traversal to apply the strategies to
- */
- public void applyStrategies(final Traversal.Admin<?, ?> traversal);
-
- /**
- * Add all the provided {@link TraversalStrategy} instances to the current collection.
- * When all the provided strategies have been added, the collection is resorted.
- *
- * @param strategies the traversal strategies to add
- * @return the newly updated/sorted traversal strategies collection
- */
- public TraversalStrategies addStrategies(final TraversalStrategy<?>... strategies);
-
- /**
- * Remove all the provided {@link TraversalStrategy} classes from the current collection.
- * When all the provided strategies have been removed, the collection is resorted.
- *
- * @param strategyClasses the traversal strategies to remove by their class
- * @return the newly updated/sorted traversal strategies collection
- */
- @SuppressWarnings({"unchecked", "varargs"})
- public TraversalStrategies removeStrategies(final Class<? extends TraversalStrategy>... strategyClasses);
-
- @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
- public TraversalStrategies clone();
-
- /**
* Sorts the list of provided strategies such that the {@link TraversalStrategy#applyPost()}
* and {@link TraversalStrategy#applyPrior()} dependencies are respected.
* <p/>
@@ -174,7 +129,6 @@ public interface TraversalStrategies extends Serializable, Cloneable {
return sortedStrategies;
}
-
static void visit(Map<Class<? extends TraversalStrategy>, Set<Class<? extends TraversalStrategy>>> dependencyMap, List<Class<? extends TraversalStrategy>> sortedStrategyClasses, Set<Class<? extends TraversalStrategy>> seenStrategyClases, List<Class<? extends TraversalStrategy>> unprocessedStrategyClasses, Class<? extends TraversalStrategy> strategyClass) {
if (seenStrategyClases.contains(strategyClass)) {
throw new IllegalStateException("Cyclic dependency between traversal strategies: ["
@@ -193,6 +147,51 @@ public interface TraversalStrategies extends Serializable, Cloneable {
}
}
+ /**
+ * Return all the {@link TraversalStrategy} singleton instances associated with this {@link TraversalStrategies}.
+ */
+ public List<TraversalStrategy<?>> toList();
+
+ /**
+ * Return the {@link TraversalStrategy} instance associated with the provided class.
+ *
+ * @param traversalStrategyClass the class of the strategy to get
+ * @param <T> the strategy class type
+ * @return an optional containing the strategy instance or not
+ */
+ public default <T extends TraversalStrategy> Optional<T> getStrategy(final Class<T> traversalStrategyClass) {
+ return (Optional) toList().stream().filter(s -> traversalStrategyClass.isAssignableFrom(s.getClass())).findAny();
+ }
+
+ /**
+ * Apply all the {@link TraversalStrategy} optimizers to the {@link Traversal} for the stated {@link TraversalEngine}.
+ * This method must ensure that the strategies are sorted prior to application.
+ *
+ * @param traversal the traversal to apply the strategies to
+ */
+ public void applyStrategies(final Traversal.Admin<?, ?> traversal);
+
+ /**
+ * Add all the provided {@link TraversalStrategy} instances to the current collection.
+ * When all the provided strategies have been added, the collection is resorted.
+ *
+ * @param strategies the traversal strategies to add
+ * @return the newly updated/sorted traversal strategies collection
+ */
+ public TraversalStrategies addStrategies(final TraversalStrategy<?>... strategies);
+
+ /**
+ * Remove all the provided {@link TraversalStrategy} classes from the current collection.
+ * When all the provided strategies have been removed, the collection is resorted.
+ *
+ * @param strategyClasses the traversal strategies to remove by their class
+ * @return the newly updated/sorted traversal strategies collection
+ */
+ @SuppressWarnings({"unchecked", "varargs"})
+ public TraversalStrategies removeStrategies(final Class<? extends TraversalStrategy>... strategyClasses);
+
+ @SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
+ public TraversalStrategies clone();
public static final class GlobalCache {
@@ -208,6 +207,7 @@ public interface TraversalStrategies extends Serializable, Cloneable {
AdjacentToIncidentStrategy.instance(),
FilterRankingStrategy.instance(),
MatchPredicateStrategy.instance(),
+ NoBarrierStrategy.instance(),
RepeatUnrollStrategy.instance(),
RangeByIsCountStrategy.instance(),
PathRetractionStrategy.instance(),
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/lambda/AbstractLambdaTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/lambda/AbstractLambdaTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/lambda/AbstractLambdaTraversal.java
index 8f910a0..aada4e4 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/lambda/AbstractLambdaTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/lambda/AbstractLambdaTraversal.java
@@ -52,20 +52,19 @@ public abstract class AbstractLambdaTraversal<S, E> implements Traversal.Admin<S
}
@Override
- public List<Step> getSteps() {
- return null == this.bypassTraversal ? Collections.emptyList() : this.bypassTraversal.getSteps();
- }
-
- @Override
public Bytecode getBytecode() {
return null == this.bypassTraversal ? new Bytecode() : this.bypassTraversal.getBytecode();
}
-
@Override
- public void reset() {
+ public void addStart(final Traverser.Admin<S> start) {
if (null != this.bypassTraversal)
- this.bypassTraversal.reset();
+ this.bypassTraversal.addStart(start);
+ }
+
+ @Override
+ public List<Step> getSteps() {
+ return null == this.bypassTraversal ? Collections.emptyList() : this.bypassTraversal.getSteps();
}
@Override
@@ -90,9 +89,14 @@ public abstract class AbstractLambdaTraversal<S, E> implements Traversal.Admin<S
}
@Override
- public void setSideEffects(final TraversalSideEffects sideEffects) {
+ public Set<TraverserRequirement> getTraverserRequirements() {
+ return null == this.bypassTraversal ? REQUIREMENTS : this.bypassTraversal.getTraverserRequirements();
+ }
+
+ @Override
+ public void reset() {
if (null != this.bypassTraversal)
- this.bypassTraversal.setSideEffects(sideEffects);
+ this.bypassTraversal.reset();
}
@Override
@@ -101,9 +105,9 @@ public abstract class AbstractLambdaTraversal<S, E> implements Traversal.Admin<S
}
@Override
- public void setStrategies(final TraversalStrategies strategies) {
+ public void setSideEffects(final TraversalSideEffects sideEffects) {
if (null != this.bypassTraversal)
- this.bypassTraversal.setStrategies(strategies);
+ this.bypassTraversal.setSideEffects(sideEffects);
}
@Override
@@ -112,53 +116,33 @@ public abstract class AbstractLambdaTraversal<S, E> implements Traversal.Admin<S
}
@Override
- public void setParent(final TraversalParent step) {
- if (null != this.bypassTraversal) {
- this.bypassTraversal.setParent(step);
- step.integrateChild(this.bypassTraversal);
- }
- }
-
- @Override
- public TraversalParent getParent() {
- return null == this.bypassTraversal ? EmptyStep.instance() : this.bypassTraversal.getParent();
- }
-
- @Override
- public Traversal.Admin<S, E> clone() {
- try {
- final AbstractLambdaTraversal<S, E> clone = (AbstractLambdaTraversal<S, E>) super.clone();
- if (null != this.bypassTraversal)
- clone.bypassTraversal = this.bypassTraversal.clone();
- return clone;
- } catch (final CloneNotSupportedException e) {
- throw new IllegalStateException(e.getMessage(), e);
- }
+ public void setStrategies(final TraversalStrategies strategies) {
+ if (null != this.bypassTraversal)
+ this.bypassTraversal.setStrategies(strategies);
}
@Override
- public E next() {
- if (null != this.bypassTraversal)
- return this.bypassTraversal.next();
- throw new UnsupportedOperationException("The " + this.getClass().getSimpleName() + " can only be used as a predicate traversal");
+ public <T> Optional<T> metadata(final String key) {
+ return null == this.bypassTraversal ? Optional.empty() : this.bypassTraversal.metadata(key);
}
@Override
- public Traverser.Admin<E> nextTraverser() {
+ public <T> void metadata(final String key, final T value) {
if (null != this.bypassTraversal)
- return this.bypassTraversal.nextTraverser();
- throw new UnsupportedOperationException("The " + this.getClass().getSimpleName() + " can only be used as a predicate traversal");
+ this.bypassTraversal.metadata(key, value);
}
@Override
- public boolean hasNext() {
- return null == this.bypassTraversal || this.bypassTraversal.hasNext();
+ public TraversalParent getParent() {
+ return null == this.bypassTraversal ? EmptyStep.instance() : this.bypassTraversal.getParent();
}
@Override
- public void addStart(final Traverser.Admin<S> start) {
- if (null != this.bypassTraversal)
- this.bypassTraversal.addStart(start);
+ public void setParent(final TraversalParent step) {
+ if (null != this.bypassTraversal) {
+ this.bypassTraversal.setParent(step);
+ step.integrateChild(this.bypassTraversal);
+ }
}
@Override
@@ -179,8 +163,22 @@ public abstract class AbstractLambdaTraversal<S, E> implements Traversal.Admin<S
}
@Override
- public Set<TraverserRequirement> getTraverserRequirements() {
- return null == this.bypassTraversal ? REQUIREMENTS : this.bypassTraversal.getTraverserRequirements();
+ public Traverser.Admin<E> nextTraverser() {
+ if (null != this.bypassTraversal)
+ return this.bypassTraversal.nextTraverser();
+ throw new UnsupportedOperationException("The " + this.getClass().getSimpleName() + " can only be used as a predicate traversal");
+ }
+
+ @Override
+ public boolean hasNext() {
+ return null == this.bypassTraversal || this.bypassTraversal.hasNext();
+ }
+
+ @Override
+ public E next() {
+ if (null != this.bypassTraversal)
+ return this.bypassTraversal.next();
+ throw new UnsupportedOperationException("The " + this.getClass().getSimpleName() + " can only be used as a predicate traversal");
}
@Override
@@ -193,4 +191,16 @@ public abstract class AbstractLambdaTraversal<S, E> implements Traversal.Admin<S
return this.getClass().equals(object.getClass()) && this.hashCode() == object.hashCode();
}
+ @Override
+ public Traversal.Admin<S, E> clone() {
+ try {
+ final AbstractLambdaTraversal<S, E> clone = (AbstractLambdaTraversal<S, E>) super.clone();
+ if (null != this.bypassTraversal)
+ clone.bypassTraversal = this.bypassTraversal.clone();
+ return clone;
+ } catch (final CloneNotSupportedException e) {
+ throw new IllegalStateException(e.getMessage(), e);
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java
index db8b17c..cb0207e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/LazyBarrierStrategy.java
@@ -33,10 +33,10 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.ProfileStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
-import org.apache.tinkerpop.gremlin.process.traversal.util.SideEffectHelper;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -74,7 +74,8 @@ public final class LazyBarrierStrategy extends AbstractTraversalStrategy<Travers
TraversalHelper.hasStepOfAssignableClass(ProfileSideEffectStep.class, TraversalHelper.getRootTraversal(traversal)))) // necessary cause ProfileTest analyzes counts
return;
- final Set<String> frozenStepIds = SideEffectHelper.determineFrozenStepIds(traversal);
+ final Set<String> frozenStepIds = TraversalHelper.getRootTraversal(traversal)
+ .<Set<String>>metadata(NoBarrierStrategy.FROZEN_STEPS_METADATA_KEY).orElse(Collections.emptySet());
boolean foundFlatMap = false;
boolean labeledPath = false;
for (int i = 0; i < traversal.getSteps().size(); i++) {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/NoBarrierStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/NoBarrierStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/NoBarrierStrategy.java
new file mode 100644
index 0000000..6c01cfc
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/NoBarrierStrategy.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
+import org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder;
+import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
+import org.apache.tinkerpop.gremlin.process.traversal.step.SideEffectCapable;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ */
+public class NoBarrierStrategy extends AbstractTraversalStrategy<TraversalStrategy.OptimizationStrategy>
+ implements TraversalStrategy.OptimizationStrategy {
+
+ static final String FROZEN_STEPS_METADATA_KEY = "gremlin.noBarrier.frozenSteps";
+ private static final NoBarrierStrategy INSTANCE = new NoBarrierStrategy();
+ private final Set<Class<? extends OptimizationStrategy>> postStrategies;
+
+ private NoBarrierStrategy() {
+ postStrategies = new HashSet<>(2);
+ postStrategies.add(LazyBarrierStrategy.class);
+ postStrategies.add(PathRetractionStrategy.class);
+ }
+
+ private static void processSideEffectSteps(final Set<String> activeSideEffectKeys,
+ final Map<String, LinkedList<List<String>>> frozenStepIdMap,
+ final Traversal.Admin<?, ?> traversal) {
+ for (final Step step : traversal.getSteps()) {
+ if (step instanceof SideEffectCapable && !(step instanceof Barrier)) {
+ final String sideEffectKey = ((SideEffectCapable) step).getSideEffectKey();
+ if (!frozenStepIdMap.containsKey(sideEffectKey)) {
+ frozenStepIdMap.put(sideEffectKey, new LinkedList<>());
+ frozenStepIdMap.get(sideEffectKey).add(new ArrayList<>());
+ }
+ activeSideEffectKeys.add(sideEffectKey);
+ continue;
+ }
+ if (step instanceof Barrier) {
+ activeSideEffectKeys.clear();
+ for (final LinkedList<List<String>> list : frozenStepIdMap.values()) {
+ if (!list.getLast().isEmpty()) {
+ list.add(new ArrayList<>());
+ }
+ }
+ }
+ if (activeSideEffectKeys.isEmpty()) {
+ continue;
+ }
+ for (final String key : activeSideEffectKeys) {
+ frozenStepIdMap.get(key).getLast().add(step.getId());
+ }
+ if (step instanceof Scoping && step.getRequirements().contains(TraverserRequirement.SIDE_EFFECTS)) {
+ for (final String key : ((Scoping) step).getScopeKeys()) {
+ if (frozenStepIdMap.containsKey(key) && activeSideEffectKeys.contains(key)) {
+ frozenStepIdMap.get(key).add(new ArrayList<>());
+ }
+ }
+ } else if (step instanceof LambdaHolder) {
+ for (final LinkedList<List<String>> list : frozenStepIdMap.values()) {
+ list.add(new ArrayList<>());
+ }
+ } else if (step instanceof TraversalParent) {
+ final TraversalParent traversalParent = (TraversalParent) step;
+ traversalParent.getGlobalChildren().forEach(t -> processSideEffectSteps(activeSideEffectKeys, frozenStepIdMap, t));
+ traversalParent.getLocalChildren().forEach(t -> processSideEffectSteps(activeSideEffectKeys, frozenStepIdMap, t));
+ }
+ }
+ }
+
+ public static NoBarrierStrategy instance() {
+ return INSTANCE;
+ }
+
+ @Override
+ public void apply(final Traversal.Admin<?, ?> traversal) {
+ if (traversal.getParent() instanceof EmptyStep && !TraversalHelper.onGraphComputer(traversal)) {
+ final Set<String> frozenStepIds = new HashSet<>();
+ if (!TraversalHelper.onGraphComputer(traversal)) {
+ final Map<String, LinkedList<List<String>>> frozenStepIdMap = new HashMap<>();
+ processSideEffectSteps(new HashSet<>(), frozenStepIdMap, traversal);
+ for (final LinkedList<List<String>> list : frozenStepIdMap.values()) {
+ list.removeLast();
+ list.forEach(frozenStepIds::addAll);
+ }
+ }
+ traversal.metadata(FROZEN_STEPS_METADATA_KEY, frozenStepIds);
+ }
+ }
+
+ @Override
+ public Set<Class<? extends OptimizationStrategy>> applyPost() {
+ return postStrategies;
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
index 700fdfd..92a8c06 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PathRetractionStrategy.java
@@ -32,7 +32,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
import org.apache.tinkerpop.gremlin.process.traversal.util.PathUtil;
-import org.apache.tinkerpop.gremlin.process.traversal.util.SideEffectHelper;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.javatuples.Pair;
@@ -71,7 +70,8 @@ public final class PathRetractionStrategy extends AbstractTraversalStrategy<Trav
if (TraversalHelper.anyStepRecursively(step -> (step instanceof LambdaHolder || step.getRequirements().contains(TraverserRequirement.PATH)), TraversalHelper.getRootTraversal(traversal)))
return;
- final Set<String> frozenStepIds = SideEffectHelper.determineFrozenStepIds(traversal);
+ final Set<String> frozenStepIds = TraversalHelper.getRootTraversal(traversal)
+ .<Set<String>>metadata(NoBarrierStrategy.FROZEN_STEPS_METADATA_KEY).orElse(Collections.emptySet());
final boolean onGraphComputer = TraversalHelper.onGraphComputer(traversal);
final Set<String> foundLabels = new HashSet<>();
final Set<String> keepLabels = new HashSet<>();
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
index 3c21e37..27a0451 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
@@ -37,9 +37,11 @@ import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.Set;
@@ -49,8 +51,8 @@ import java.util.Set;
*/
public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
- private Traverser.Admin<E> lastTraverser = EmptyTraverser.instance();
- private Step<?, E> finalEndStep = EmptyStep.instance();
+ protected final Bytecode bytecode; // TODO: perhaps make transient until 3.3.0?
+ protected final Map<String, Object> metadata;
private final StepPosition stepPosition = new StepPosition();
protected transient Graph graph;
protected List<Step> steps = new ArrayList<>();
@@ -62,13 +64,15 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
protected transient TraverserGenerator generator;
protected Set<TraverserRequirement> requirements;
protected boolean locked = false;
- protected final Bytecode bytecode; // TODO: perhaps make transient until 3.3.0?
+ private Traverser.Admin<E> lastTraverser = EmptyTraverser.instance();
+ private Step<?, E> finalEndStep = EmptyStep.instance();
private DefaultTraversal(final Graph graph, final TraversalStrategies traversalStrategies, final Bytecode bytecode) {
this.graph = graph;
this.strategies = traversalStrategies;
this.bytecode = bytecode;
+ this.metadata = new HashMap<>();
}
public DefaultTraversal(final Graph graph) {
@@ -94,17 +98,57 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
}
@Override
- public Traversal.Admin<S, E> asAdmin() {
- return this;
+ public void addStarts(final Iterator<Traverser.Admin<S>> starts) {
+ if (!this.locked) this.applyStrategies();
+ if (!this.steps.isEmpty()) this.steps.get(0).addStarts(starts);
}
@Override
- public TraverserGenerator getTraverserGenerator() {
- if (null == this.generator)
- this.generator = (this.parent instanceof EmptyStep) ?
- DefaultTraverserGeneratorFactory.instance().getTraverserGenerator(this.getTraverserRequirements()) :
- TraversalHelper.getRootTraversal(this).getTraverserGenerator();
- return this.generator;
+ public void addStart(final Traverser.Admin<S> start) {
+ if (!this.locked) this.applyStrategies();
+ if (!this.steps.isEmpty()) this.steps.get(0).addStart(start);
+ }
+
+ @Override
+ public List<Step> getSteps() {
+ return this.unmodifiableSteps;
+ }
+
+ @Override
+ public <S2, E2> Traversal.Admin<S2, E2> addStep(final int index, final Step<?, ?> step) throws IllegalStateException {
+ if (this.locked) throw Exceptions.traversalIsLocked();
+ step.setId(this.stepPosition.nextXId());
+ this.steps.add(index, step);
+ final Step previousStep = this.steps.size() > 0 && index != 0 ? steps.get(index - 1) : null;
+ final Step nextStep = this.steps.size() > index + 1 ? steps.get(index + 1) : null;
+ step.setPreviousStep(null != previousStep ? previousStep : EmptyStep.instance());
+ step.setNextStep(null != nextStep ? nextStep : EmptyStep.instance());
+ if (null != previousStep) previousStep.setNextStep(step);
+ if (null != nextStep) nextStep.setPreviousStep(step);
+ step.setTraversal(this);
+ return (Traversal.Admin<S2, E2>) this;
+ }
+
+ @Override
+ public <S2, E2> Traversal.Admin<S2, E2> removeStep(final int index) throws IllegalStateException {
+ if (this.locked) throw Exceptions.traversalIsLocked();
+ final Step previousStep = this.steps.size() > 0 && index != 0 ? steps.get(index - 1) : null;
+ final Step nextStep = this.steps.size() > index + 1 ? steps.get(index + 1) : null;
+ //this.steps.get(index).setTraversal(EmptyTraversal.instance());
+ this.steps.remove(index);
+ if (null != previousStep) previousStep.setNextStep(null == nextStep ? EmptyStep.instance() : nextStep);
+ if (null != nextStep) nextStep.setPreviousStep(null == previousStep ? EmptyStep.instance() : previousStep);
+ return (Traversal.Admin<S2, E2>) this;
+ }
+
+ @Override
+ public Step<S, ?> getStartStep() {
+ return this.steps.isEmpty() ? EmptyStep.instance() : this.steps.get(0);
+ }
+
+ @Override
+ public Step<?, E> getEndStep() {
+ return this.steps.isEmpty() ? EmptyStep.instance() : this.steps.get(this.steps.size() - 1);
}
@Override
@@ -139,6 +183,15 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
}
@Override
+ public TraverserGenerator getTraverserGenerator() {
+ if (null == this.generator)
+ this.generator = (this.parent instanceof EmptyStep) ?
+ DefaultTraverserGeneratorFactory.instance().getTraverserGenerator(this.getTraverserRequirements()) :
+ TraversalHelper.getRootTraversal(this).getTraverserGenerator();
+ return this.generator;
+ }
+
+ @Override
public Set<TraverserRequirement> getTraverserRequirements() {
if (null == this.requirements) {
// if (!this.locked) this.applyStrategies();
@@ -158,8 +211,64 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
}
@Override
- public List<Step> getSteps() {
- return this.unmodifiableSteps;
+ public void reset() {
+ this.steps.forEach(Step::reset);
+ this.lastTraverser = EmptyTraverser.instance();
+ }
+
+ @Override
+ public TraversalSideEffects getSideEffects() {
+ return this.sideEffects;
+ }
+
+ @Override
+ public void setSideEffects(final TraversalSideEffects sideEffects) {
+ this.sideEffects = sideEffects;
+ }
+
+ @Override
+ public TraversalStrategies getStrategies() {
+ return this.strategies;
+ }
+
+ @Override
+ public void setStrategies(final TraversalStrategies strategies) {
+ this.strategies = strategies;
+ }
+
+ @Override
+ public <T> Optional<T> metadata(final String key) {
+ return Optional.ofNullable((T) metadata.get(key));
+ }
+
+ @Override
+ public <T> void metadata(final String key, final T value) {
+ metadata.put(key, value);
+ }
+
+ @Override
+ public TraversalParent getParent() {
+ return this.parent;
+ }
+
+ @Override
+ public void setParent(final TraversalParent step) {
+ this.parent = step;
+ }
+
+ @Override
+ public boolean isLocked() {
+ return this.locked;
+ }
+
+ @Override
+ public Optional<Graph> getGraph() {
+ return Optional.ofNullable(this.graph);
+ }
+
+ @Override
+ public void setGraph(final Graph graph) {
+ this.graph = graph;
}
@Override
@@ -179,6 +288,11 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
}
@Override
+ public Traversal.Admin<S, E> asAdmin() {
+ return this;
+ }
+
+ @Override
public boolean hasNext() {
if (!this.locked) this.applyStrategies();
return this.lastTraverser.bulk() > 0L || this.finalEndStep.hasNext();
@@ -198,36 +312,18 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
}
@Override
- public void reset() {
- this.steps.forEach(Step::reset);
- this.lastTraverser = EmptyTraverser.instance();
- }
-
- @Override
- public void addStart(final Traverser.Admin<S> start) {
- if (!this.locked) this.applyStrategies();
- if (!this.steps.isEmpty()) this.steps.get(0).addStart(start);
- }
-
- @Override
- public void addStarts(final Iterator<Traverser.Admin<S>> starts) {
- if (!this.locked) this.applyStrategies();
- if (!this.steps.isEmpty()) this.steps.get(0).addStarts(starts);
- }
-
- @Override
- public String toString() {
- return StringFactory.traversalString(this);
- }
-
- @Override
- public Step<S, ?> getStartStep() {
- return this.steps.isEmpty() ? EmptyStep.instance() : this.steps.get(0);
+ public int hashCode() {
+ int index = 0;
+ int result = this.getClass().hashCode();
+ for (final Step step : this.asAdmin().getSteps()) {
+ result ^= Integer.rotateLeft(step.hashCode(), index++);
+ }
+ return result;
}
@Override
- public Step<?, E> getEndStep() {
- return this.steps.isEmpty() ? EmptyStep.instance() : this.steps.get(this.steps.size() - 1);
+ public boolean equals(final Object other) {
+ return other != null && other.getClass().equals(this.getClass()) && this.equals(((Traversal.Admin) other));
}
@Override
@@ -254,89 +350,7 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
}
@Override
- public boolean isLocked() {
- return this.locked;
- }
-
- @Override
- public void setSideEffects(final TraversalSideEffects sideEffects) {
- this.sideEffects = sideEffects;
- }
-
- @Override
- public TraversalSideEffects getSideEffects() {
- return this.sideEffects;
- }
-
- @Override
- public void setStrategies(final TraversalStrategies strategies) {
- this.strategies = strategies;
- }
-
- @Override
- public TraversalStrategies getStrategies() {
- return this.strategies;
- }
-
- @Override
- public <S2, E2> Traversal.Admin<S2, E2> addStep(final int index, final Step<?, ?> step) throws IllegalStateException {
- if (this.locked) throw Exceptions.traversalIsLocked();
- step.setId(this.stepPosition.nextXId());
- this.steps.add(index, step);
- final Step previousStep = this.steps.size() > 0 && index != 0 ? steps.get(index - 1) : null;
- final Step nextStep = this.steps.size() > index + 1 ? steps.get(index + 1) : null;
- step.setPreviousStep(null != previousStep ? previousStep : EmptyStep.instance());
- step.setNextStep(null != nextStep ? nextStep : EmptyStep.instance());
- if (null != previousStep) previousStep.setNextStep(step);
- if (null != nextStep) nextStep.setPreviousStep(step);
- step.setTraversal(this);
- return (Traversal.Admin<S2, E2>) this;
- }
-
- @Override
- public <S2, E2> Traversal.Admin<S2, E2> removeStep(final int index) throws IllegalStateException {
- if (this.locked) throw Exceptions.traversalIsLocked();
- final Step previousStep = this.steps.size() > 0 && index != 0 ? steps.get(index - 1) : null;
- final Step nextStep = this.steps.size() > index + 1 ? steps.get(index + 1) : null;
- //this.steps.get(index).setTraversal(EmptyTraversal.instance());
- this.steps.remove(index);
- if (null != previousStep) previousStep.setNextStep(null == nextStep ? EmptyStep.instance() : nextStep);
- if (null != nextStep) nextStep.setPreviousStep(null == previousStep ? EmptyStep.instance() : previousStep);
- return (Traversal.Admin<S2, E2>) this;
- }
-
- @Override
- public void setParent(final TraversalParent step) {
- this.parent = step;
- }
-
- @Override
- public TraversalParent getParent() {
- return this.parent;
- }
-
- @Override
- public Optional<Graph> getGraph() {
- return Optional.ofNullable(this.graph);
- }
-
- @Override
- public void setGraph(final Graph graph) {
- this.graph = graph;
- }
-
- @Override
- public boolean equals(final Object other) {
- return other != null && other.getClass().equals(this.getClass()) && this.equals(((Traversal.Admin) other));
- }
-
- @Override
- public int hashCode() {
- int index = 0;
- int result = this.getClass().hashCode();
- for (final Step step : this.asAdmin().getSteps()) {
- result ^= Integer.rotateLeft(step.hashCode(), index++);
- }
- return result;
+ public String toString() {
+ return StringFactory.traversalString(this);
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/EmptyTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/EmptyTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/EmptyTraversal.java
index d3f6215..552797e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/EmptyTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/EmptyTraversal.java
@@ -45,89 +45,89 @@ public final class EmptyTraversal<S, E> implements Traversal.Admin<S, E> {
private static final TraversalSideEffects SIDE_EFFECTS = EmptyTraversalSideEffects.instance();
private static final TraversalStrategies STRATEGIES = EmptyTraversalStrategies.instance();
- public static <A, B> EmptyTraversal<A, B> instance() {
- return INSTANCE;
- }
-
protected EmptyTraversal() {
}
+ public static <A, B> EmptyTraversal<A, B> instance() {
+ return INSTANCE;
+ }
+
public Bytecode getBytecode() {
return new Bytecode();
}
@Override
- public Traversal.Admin<S, E> asAdmin() {
- return this;
+ public void addStarts(final Iterator<Traverser.Admin<S>> starts) {
+
}
@Override
- public boolean hasNext() {
- return false;
+ public void addStart(final Traverser.Admin<S> start) {
+
}
@Override
- public E next() {
- throw FastNoSuchElementException.instance();
+ public List<Step> getSteps() {
+ return Collections.emptyList();
}
@Override
- public TraversalSideEffects getSideEffects() {
- return SIDE_EFFECTS;
+ public <E2> Traversal.Admin<S, E2> addStep(final Step<?, E2> step) {
+ return instance();
}
@Override
- public void applyStrategies() {
-
+ public <S2, E2> Traversal.Admin<S2, E2> addStep(final int index, final Step<?, ?> step) throws IllegalStateException {
+ return (Traversal.Admin) this;
}
@Override
- public void addStarts(final Iterator<Traverser.Admin<S>> starts) {
-
+ public <S2, E2> Traversal.Admin<S2, E2> removeStep(final int index) throws IllegalStateException {
+ return (Traversal.Admin) this;
}
@Override
- public void addStart(final Traverser.Admin<S> start) {
+ public void applyStrategies() {
}
@Override
- public <E2> Traversal.Admin<S, E2> addStep(final Step<?, E2> step) {
- return instance();
+ public TraverserGenerator getTraverserGenerator() {
+ return null;
}
@Override
- public List<Step> getSteps() {
- return Collections.emptyList();
+ public Set<TraverserRequirement> getTraverserRequirements() {
+ return Collections.emptySet();
}
@Override
- public EmptyTraversal<S, E> clone() {
- return instance();
+ public TraversalSideEffects getSideEffects() {
+ return SIDE_EFFECTS;
}
@Override
- public boolean isLocked() {
- return true;
+ public void setSideEffects(final TraversalSideEffects sideEffects) {
}
@Override
- public TraverserGenerator getTraverserGenerator() {
- return null;
+ public TraversalStrategies getStrategies() {
+ return STRATEGIES;
}
@Override
- public void setSideEffects(final TraversalSideEffects sideEffects) {
+ public void setStrategies(final TraversalStrategies traversalStrategies) {
+
}
@Override
- public TraversalStrategies getStrategies() {
- return STRATEGIES;
+ public <T> Optional<T> metadata(String key) {
+ return Optional.empty();
}
@Override
- public void setParent(final TraversalParent step) {
+ public <T> void metadata(String key, T value) {
}
@@ -137,42 +137,52 @@ public final class EmptyTraversal<S, E> implements Traversal.Admin<S, E> {
}
@Override
- public void setStrategies(final TraversalStrategies traversalStrategies) {
+ public void setParent(final TraversalParent step) {
}
@Override
- public <S2, E2> Traversal.Admin<S2, E2> addStep(final int index, final Step<?, ?> step) throws IllegalStateException {
- return (Traversal.Admin) this;
+ public boolean isLocked() {
+ return true;
}
@Override
- public <S2, E2> Traversal.Admin<S2, E2> removeStep(final int index) throws IllegalStateException {
- return (Traversal.Admin) this;
+ public Optional<Graph> getGraph() {
+ return Optional.empty();
}
@Override
- public boolean equals(final Object object) {
- return object instanceof EmptyTraversal;
+ public void setGraph(final Graph graph) {
+
}
@Override
- public int hashCode() {
- return -343564565;
+ public Traversal.Admin<S, E> asAdmin() {
+ return this;
}
@Override
- public Set<TraverserRequirement> getTraverserRequirements() {
- return Collections.emptySet();
+ public boolean hasNext() {
+ return false;
}
@Override
- public Optional<Graph> getGraph() {
- return Optional.empty();
+ public E next() {
+ throw FastNoSuchElementException.instance();
}
@Override
- public void setGraph(final Graph graph) {
+ public int hashCode() {
+ return -343564565;
+ }
+
+ @Override
+ public boolean equals(final Object object) {
+ return object instanceof EmptyTraversal;
+ }
+ @Override
+ public EmptyTraversal<S, E> clone() {
+ return instance();
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/5a8be6b9/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java
index 1193daf..d605c76 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/SideEffectHelper.java
@@ -18,23 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.process.traversal.util;
-import org.apache.tinkerpop.gremlin.process.traversal.Step;
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects;
-import org.apache.tinkerpop.gremlin.process.traversal.step.Barrier;
-import org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder;
-import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
-import org.apache.tinkerpop.gremlin.process.traversal.step.SideEffectCapable;
-import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
-import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -60,62 +44,4 @@ public final class SideEffectHelper {
SideEffectHelper.validateSideEffectKey(key);
SideEffectHelper.validateSideEffectValue(value);
}
-
- public static Set<String> determineFrozenStepIds(final Traversal.Admin<?, ?> traversal) {
- final Set<String> frozenStepIds = new HashSet<>();
- if (!TraversalHelper.onGraphComputer(traversal)) {
- final Map<String, LinkedList<List<String>>> frozenStepIdMap = new HashMap<>();
- processSideEffectSteps(new HashSet<>(), frozenStepIdMap, traversal);
- for (final LinkedList<List<String>> list : frozenStepIdMap.values()) {
- list.removeLast();
- list.forEach(frozenStepIds::addAll);
- }
- }
- return frozenStepIds;
- }
-
- private static void processSideEffectSteps(final Set<String> activeSideEffectKeys,
- final Map<String, LinkedList<List<String>>> frozenStepIdMap,
- final Traversal.Admin<?, ?> traversal) {
- for (final Step step : traversal.getSteps()) {
- if (step instanceof SideEffectCapable && !(step instanceof Barrier)) {
- final String sideEffectKey = ((SideEffectCapable) step).getSideEffectKey();
- if (!frozenStepIdMap.containsKey(sideEffectKey)) {
- frozenStepIdMap.put(sideEffectKey, new LinkedList<>());
- frozenStepIdMap.get(sideEffectKey).add(new ArrayList<>());
- }
- activeSideEffectKeys.add(sideEffectKey);
- continue;
- }
- if (step instanceof Barrier) {
- activeSideEffectKeys.clear();
- for (final LinkedList<List<String>> list : frozenStepIdMap.values()) {
- if (!list.getLast().isEmpty()) {
- list.add(new ArrayList<>());
- }
- }
- }
- if (activeSideEffectKeys.isEmpty()) {
- continue;
- }
- for (final String key : activeSideEffectKeys) {
- frozenStepIdMap.get(key).getLast().add(step.getId());
- }
- if (step instanceof Scoping && step.getRequirements().contains(TraverserRequirement.SIDE_EFFECTS)) {
- for (final String key : ((Scoping) step).getScopeKeys()) {
- if (frozenStepIdMap.containsKey(key) && activeSideEffectKeys.contains(key)) {
- frozenStepIdMap.get(key).add(new ArrayList<>());
- }
- }
- } else if (step instanceof LambdaHolder) {
- for (final LinkedList<List<String>> list : frozenStepIdMap.values()) {
- list.add(new ArrayList<>());
- }
- } else if (step instanceof TraversalParent) {
- final TraversalParent traversalParent = (TraversalParent) step;
- traversalParent.getGlobalChildren().forEach(t -> processSideEffectSteps(activeSideEffectKeys, frozenStepIdMap, t));
- traversalParent.getLocalChildren().forEach(t -> processSideEffectSteps(activeSideEffectKeys, frozenStepIdMap, t));
- }
- }
- }
}
[3/4] tinkerpop git commit: added failing store() test
Posted by dk...@apache.org.
added failing store() test
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9223f390
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9223f390
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9223f390
Branch: refs/heads/TINKERPOP-1529-variant2
Commit: 9223f39068999026d17f9cd13a0442a5d90fb881
Parents: fbefd8c
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Sun Oct 30 00:43:48 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Tue Nov 8 00:42:51 2016 +0100
----------------------------------------------------------------------
.../step/sideEffect/GroovyStoreTest.groovy | 6 +++
.../traversal/step/sideEffect/StoreTest.java | 47 ++++++++++++++++++++
2 files changed, 53 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9223f390/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyStoreTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyStoreTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyStoreTest.groovy
index 5a24f07..8d9e851 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyStoreTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/GroovyStoreTest.groovy
@@ -19,6 +19,7 @@
package org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect
import org.apache.tinkerpop.gremlin.process.traversal.Traversal
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet
import org.apache.tinkerpop.gremlin.process.traversal.util.ScriptTraversal
import org.apache.tinkerpop.gremlin.structure.Vertex
@@ -49,5 +50,10 @@ public abstract class GroovyStoreTest {
public Traversal<Vertex, Collection> get_g_V_storeXaX_byXoutEXcreatedX_countX_out_out_storeXaX_byXinEXcreatedX_weight_sumX_capXaX() {
new ScriptTraversal<>(g, "gremlin-groovy", "g.V.store('a').by(__.outE('created').count).out.out.store('a').by(__.inE('created').weight.sum).cap('a')");
}
+
+ @Override
+ public Traversal<Vertex, BulkSet<String>> get_g_V_order_byXidX_storeXaX_byXnameX_out_selectXaX() {
+ new ScriptTraversal(g, "gremlin-groovy", "g.V.order.by(id).store('a').by('name').out.select('a')")
+ }
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9223f390/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java
index 40b03ef..4f65b6f 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StoreTest.java
@@ -23,12 +23,17 @@ import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
+import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.function.HashSetSupplier;
import org.junit.Test;
import org.junit.runner.RunWith;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
import java.util.Set;
import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
@@ -43,6 +48,14 @@ import static org.junit.Assert.assertTrue;
*/
@RunWith(GremlinProcessRunner.class)
public abstract class StoreTest extends AbstractGremlinProcessTest {
+
+ @SafeVarargs
+ private static <E> BulkSet<E> makeBulkSet(final E... elements) {
+ final BulkSet<E> result = new BulkSet<>();
+ Collections.addAll(result, elements);
+ return result;
+ }
+
public abstract Traversal<Vertex, Collection> get_g_V_storeXaX_byXnameX_out_capXaX();
public abstract Traversal<Vertex, Collection> get_g_VX1X_storeXaX_byXnameX_out_storeXaX_byXnameX_name_capXaX(final Object v1Id);
@@ -51,6 +64,8 @@ public abstract class StoreTest extends AbstractGremlinProcessTest {
public abstract Traversal<Vertex, Collection> get_g_V_storeXaX_byXoutEXcreatedX_countX_out_out_storeXaX_byXinEXcreatedX_weight_sumX_capXaX();
+ public abstract Traversal<Vertex, BulkSet<String>> get_g_V_order_byXidX_storeXaX_byXnameX_out_selectXaX();
+
@Test
@LoadGraphWith(MODERN)
public void g_V_storeXa_nameX_out_capXaX() {
@@ -114,6 +129,33 @@ public abstract class StoreTest extends AbstractGremlinProcessTest {
assertFalse(store.isEmpty());
}
+ @Test
+ @LoadGraphWith(MODERN)
+ public void g_V_order_byXidX_storeXaX_byXnameX_out_selectXaX() {
+ final Traversal<Vertex, BulkSet<String>> traversal = get_g_V_order_byXidX_storeXaX_byXnameX_out_selectXaX();
+ printTraversalForm(traversal);
+ final List<BulkSet<String>> expected = new ArrayList<>(6);
+ expected.addAll(Arrays.asList(
+ makeBulkSet("marko"),
+ makeBulkSet("marko"),
+ makeBulkSet("marko"),
+ makeBulkSet("marko", "vadas", "lop", "josh"),
+ makeBulkSet("marko", "vadas", "lop", "josh"),
+ makeBulkSet("marko", "vadas", "lop", "josh", "ripple", "peter")));
+ while (traversal.hasNext()) {
+ final BulkSet<String> a = traversal.next();
+ boolean match = false;
+ for (int i = 0; i < expected.size(); i++) {
+ if (match = expected.get(i).equals(a)) {
+ expected.remove(i);
+ break;
+ }
+ }
+ assertTrue(match);
+ }
+ assertTrue(expected.isEmpty());
+ }
+
public static class Traversals extends StoreTest {
@Override
public Traversal<Vertex, Collection> get_g_V_storeXaX_byXnameX_out_capXaX() {
@@ -134,5 +176,10 @@ public abstract class StoreTest extends AbstractGremlinProcessTest {
public Traversal<Vertex, Collection> get_g_V_storeXaX_byXoutEXcreatedX_countX_out_out_storeXaX_byXinEXcreatedX_weight_sumX_capXaX() {
return g.V().store("a").by(outE("created").count()).out().out().store("a").by(inE("created").values("weight").sum()).cap("a");
}
+
+ @Override
+ public Traversal<Vertex, BulkSet<String>> get_g_V_order_byXidX_storeXaX_byXnameX_out_selectXaX() {
+ return g.V().order().by(T.id).store("a").by("name").out().select("a");
+ }
}
}