You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/07/12 17:53:03 UTC
[2/2] tinkerpop git commit: a better generator for referenced labels
in MatchStep related to PathRetractionStrategy. One more issue I found is
coming up next and then I'm moving on from this. CTR.
a better generator for referenced labels in MatchStep related to PathRetractionStrategy. One more issue I found is coming up next and then I'm moving on from this. CTR.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/4894b67c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/4894b67c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/4894b67c
Branch: refs/heads/master
Commit: 4894b67c91517464b798648133fbee3c7c5d6e25
Parents: 402cad1
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jul 12 10:47:46 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jul 12 11:52:56 2016 -0600
----------------------------------------------------------------------
.../process/traversal/step/map/MatchStep.java | 27 +++++++++++---------
.../structure/TinkerGraphPlayTest.java | 16 +++++++-----
2 files changed, 24 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4894b67c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
index 768d906..6ac1786 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
@@ -80,7 +80,7 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
private final String computedStartLabel;
private MatchAlgorithm matchAlgorithm;
private Class<? extends MatchAlgorithm> matchAlgorithmClass = CountMatchAlgorithm.class; // default is CountMatchAlgorithm (use MatchAlgorithmStrategy to change)
- private final Map<String, Set<String>> referencedLabelsMap = new HashMap<>(); // memoization of referenced labels for MatchEndSteps (Map<startStepId, referencedLabels>)
+ private Map<String, Set<String>> referencedLabelsMap; // memoization of referenced labels for MatchEndSteps (Map<startStepId, referencedLabels>)
private Set<List<Object>> dedups = null;
private Set<String> dedupLabels = null;
@@ -338,14 +338,18 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
return false;
}
- private void generatedReferencedLabelsMap() {
- for (final Traversal.Admin<?, ?> traversal : this.matchTraversals) {
- final Set<String> referencedLabels = new HashSet<>();
- for (final Step<?, ?> step : traversal.getSteps()) {
- referencedLabels.addAll(PathUtil.getReferencedLabels(step));
+ private Map<String, Set<String>> getReferencedLabelsMap() {
+ if (null == this.referencedLabelsMap) {
+ this.referencedLabelsMap = new HashMap<>();
+ for (final Traversal.Admin<?, ?> traversal : this.matchTraversals) {
+ final Set<String> referencedLabels = new HashSet<>();
+ for (final Step<?, ?> step : traversal.getSteps()) {
+ referencedLabels.addAll(PathUtil.getReferencedLabels(step));
+ }
+ this.referencedLabelsMap.put(traversal.getStartStep().getId(), referencedLabels);
}
- this.referencedLabelsMap.put(traversal.getStartStep().getId(), referencedLabels);
}
+ return this.referencedLabelsMap;
}
private final TraverserSet standardAlgorithmBarrier = new TraverserSet();
@@ -356,7 +360,6 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
if (this.first) {
this.first = false;
- this.generatedReferencedLabelsMap();
this.initializeMatchAlgorithm(TraversalEngine.Type.STANDARD);
} else if (this.standardAlgorithmBarrier.isEmpty()) {
for (final Traversal.Admin<?, ?> matchTraversal : this.matchTraversals) {
@@ -401,7 +404,6 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
while (true) {
if (this.first) {
this.first = false;
- this.generatedReferencedLabelsMap();
this.initializeMatchAlgorithm(TraversalEngine.Type.COMPUTER);
}
final Traverser.Admin traverser = this.starts.next();
@@ -523,9 +525,10 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
return traverser;
final Set<String> keepers = new HashSet<>(this.parent.getKeepLabels());
final Set<String> tags = traverser.getTags();
- for (final Traversal.Admin<?, ?> matchTraversal : this.parent.matchTraversals) { // get remaining traversal patterns for the traverser
- if (!tags.contains(matchTraversal.getStartStep().getId())) {
- keepers.addAll(this.parent.referencedLabelsMap.get(matchTraversal.getStartStep().getId())); // get the reference labels required for those remaining traversals
+ for (final Traversal.Admin<?, ?> matchTraversal : this.parent.getGlobalChildren()) { // get remaining traversal patterns for the traverser
+ final String startStepId = matchTraversal.getStartStep().getId();
+ if (!tags.contains(startStepId)) {
+ keepers.addAll(this.parent.getReferencedLabelsMap().get(startStepId)); // get the reference labels required for those remaining traversals
}
}
return PathProcessor.processTraverserPathLabels(traverser, keepers); // remove all reference labels that are no longer required
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/4894b67c/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index 7237dfa..3554b34 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -69,14 +69,16 @@ public class TinkerGraphPlayTest {
graph.io(GraphMLIo.build()).readGraph("../data/grateful-dead.xml");
//Graph graph = TinkerFactory.createModern();
- GraphTraversalSource g = graph.traversal().withStrategies(PathRetractionStrategy.instance());
- GraphTraversalSource h = graph.traversal().withoutStrategies(PathRetractionStrategy.class);
-
- for (final GraphTraversalSource source : Arrays.asList(h, g)) {
- System.out.println(source.V().match(
+ GraphTraversalSource a = graph.traversal().withComputer().withStrategies(PathRetractionStrategy.instance()); // .withStrategies(MatchAlgorithmStrategy.build().algorithm(MatchStep.CountMatchAlgorithm.class).create());
+ GraphTraversalSource b = graph.traversal().withComputer().withoutStrategies(PathRetractionStrategy.class); //.withStrategies(MatchAlgorithmStrategy.build().algorithm(MatchStep.CountMatchAlgorithm.class).create());
+ GraphTraversalSource c = graph.traversal().withStrategies(PathRetractionStrategy.instance()); // .withStrategies(MatchAlgorithmStrategy.build().algorithm(MatchStep.CountMatchAlgorithm.class).create());
+ GraphTraversalSource d = graph.traversal().withoutStrategies(PathRetractionStrategy.class); //.withStrategies(MatchAlgorithmStrategy.build().algorithm(MatchStep.CountMatchAlgorithm.class).create());
+
+ for (final GraphTraversalSource source : Arrays.asList(d, c, b, a)) {
+ System.out.println(source + "--PathRetractionStrategy[" + source.getStrategies().toList().contains(PathRetractionStrategy.instance()) + "]");
+ System.out.println(TimeUtil.clockWithResult(2, () -> source.V().match(
__.as("a").out().as("b"),
- __.as("b").out().as("c"),
- __.as("c").out().as("d")).select("d").count().profile().next());
+ __.as("a").both().as("c")).select("a").count().next()));
}
}