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 2015/06/22 20:11:22 UTC
incubator-tinkerpop git commit: added StartStep.isVariableStartStep()
which makes testing for as('a').out()... style traversals less error prone in
WhereStep, MatchStep, ConjunctionStrategy,
etc. Fixed up respective steps/strategies to rely on this metho
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master ce8597d9a -> a748204f0
added StartStep.isVariableStartStep() which makes testing for as('a').out()... style traversals less error prone in WhereStep, MatchStep, ConjunctionStrategy, etc. Fixed up respective steps/strategies to rely on this method now. Oh -- a 'variable start step' is one that has start==null, a single step label, and is StartStep, not an extension of it.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/a748204f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/a748204f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/a748204f
Branch: refs/heads/master
Commit: a748204f0c1a43ffce5545a222d8ec1893a07f11
Parents: ce8597d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Jun 22 12:11:18 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Jun 22 12:11:18 2015 -0600
----------------------------------------------------------------------
.../gremlin/process/traversal/step/filter/WhereStep.java | 6 ++----
.../gremlin/process/traversal/step/map/MatchStep.java | 8 +++-----
.../gremlin/process/traversal/step/sideEffect/StartStep.java | 6 +++++-
.../traversal/strategy/decoration/ConjunctionStrategy.java | 4 +---
.../gremlin/process/traversal/util/TraversalHelper.java | 4 ++--
5 files changed, 13 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a748204f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
index 67ec7b4..e4e73df 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereStep.java
@@ -91,10 +91,8 @@ public final class WhereStep<S> extends FilterStep<S> implements TraversalParent
final Step<?, ?> startStep = whereTraversal.getStartStep();
if (startStep instanceof ConjunctionStep || startStep instanceof NotStep) { // for conjunction- and not-steps
((TraversalParent) startStep).getLocalChildren().forEach(this::configureStartAndEndSteps);
- } else if (startStep instanceof StartStep && !startStep.getLabels().isEmpty()) { // as("a").out()... traversals
- if (startStep.getLabels().size() > 1)
- throw new IllegalArgumentException("The start step of a where()-traversal can only have one label: " + startStep);
- final String label = startStep.getLabels().iterator().next();
+ } else if (startStep instanceof StartStep && ((StartStep) startStep).isVariableStartStep()) { // as("a").out()... traversals
+ final String label = startStep.getLabels().iterator().next();
this.scopeKeys.add(label);
TraversalHelper.replaceStep(startStep, new WhereStartStep(whereTraversal, label), whereTraversal);
this.variables.add(Variable.START);
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a748204f/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 c7b3a1a..c206321 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>>
this.conjunction = conjunction;
this.startKey = startKey;
if (null != this.startKey) {
- if (this.traversal.getEndStep() instanceof StartStep) // in case a match() is after the start step
+ if (this.traversal.getEndStep() instanceof StartStep && ((StartStep) this.traversal.getEndStep()).isVariableStartStep()) // in case a match() is after the start step
this.traversal.addStep(new IdentityStep<>(this.traversal));
this.traversal.getEndStep().addLabel(this.startKey);
}
@@ -100,9 +100,7 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
TraversalHelper.replaceStep(startStep, matchStep, matchTraversal);
this.matchStartLabels.addAll(matchStep.matchStartLabels);
this.matchEndLabels.addAll(matchStep.matchEndLabels);
- } else if (startStep instanceof StartStep) {
- if (startStep.getLabels().size() != 1)
- throw new IllegalArgumentException("The start step of a match()-traversal must have one and only one label: " + startStep);
+ } else if (startStep instanceof StartStep && ((StartStep) startStep).isVariableStartStep()) {
final String label = startStep.getLabels().iterator().next();
this.matchStartLabels.add(label);
TraversalHelper.replaceStep((Step) matchTraversal.getStartStep(), new MatchStartStep(matchTraversal, label), matchTraversal);
@@ -119,7 +117,7 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
}
}
} else {
- throw new IllegalArgumentException("All match()-traversals must have a start label (i.e. variable): " + matchTraversal);
+ throw new IllegalArgumentException("All match()-traversals must have a single start label (i.e. variable): " + matchTraversal);
}
// END STEP to XMatchEndStep
final Step<?, ?> endStep = matchTraversal.getEndStep();
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a748204f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java
index 43f3e37..7fdbd81 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/sideEffect/StartStep.java
@@ -71,7 +71,7 @@ public class StartStep<S> extends AbstractStep<S, S> {
public StartStep<S> clone() {
final StartStep<S> clone = (StartStep<S>) super.clone();
clone.first = true;
- clone.start = null;
+ clone.start = null; // TODO: is this good?
return clone;
}
@@ -92,4 +92,8 @@ public class StartStep<S> extends AbstractStep<S, S> {
}
return result;
}
+
+ public boolean isVariableStartStep() {
+ return null == this.start && this.getClass().equals(StartStep.class) && this.getLabels().size() == 1;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a748204f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConjunctionStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConjunctionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConjunctionStrategy.java
index b88a917..1fb6051 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConjunctionStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ConjunctionStrategy.java
@@ -25,7 +25,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.AndStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.ConjunctionStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.OrStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GraphStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.StartStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.ComputerAwareStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
@@ -61,8 +60,7 @@ public final class ConjunctionStrategy extends AbstractTraversalStrategy<Travers
}
private static boolean legalCurrentStep(final Step<?, ?> step) {
- return !(step instanceof EmptyStep || step instanceof GraphStep || step instanceof ComputerAwareStep.EndStep ||
- (step instanceof StartStep && (null != ((StartStep) step).getStart() || step.getLabels().isEmpty())));
+ return !(step instanceof EmptyStep || step instanceof ComputerAwareStep.EndStep || (step instanceof StartStep && !((StartStep) step).isVariableStartStep()));
}
private static void processConjunctionMarkers(final Traversal.Admin<?, ?> traversal) {
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a748204f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
index f4e3ab4..aab5b78 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
@@ -337,9 +337,9 @@ public final class TraversalHelper {
private static Set<Scoping.Variable> getVariableLocations(final Set<Scoping.Variable> variables, final Traversal.Admin<?, ?> traversal) {
if (variables.size() == 2) return variables;
final Step<?, ?> startStep = traversal.getStartStep();
- if (startStep instanceof StartStep && !startStep.getLabels().isEmpty())
+ if (startStep instanceof StartStep && ((StartStep) startStep).isVariableStartStep())
variables.add(Scoping.Variable.START);
- else if(startStep instanceof Scoping)
+ else if (startStep instanceof Scoping)
variables.addAll(((Scoping) startStep).getVariableLocations());
else if (startStep instanceof ConjunctionStep || startStep instanceof NotStep)
((TraversalParent) startStep).getLocalChildren().forEach(child -> TraversalHelper.getVariableLocations(variables, child));