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 16:42:51 UTC

incubator-tinkerpop git commit: where(P) is now explicit in GraphTraversal and __. With where(out()) going to filter(out()), ScopingStrategy is now simpler.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 88a93ae89 -> 167cd8d5a


where(P<String>) is now explicit in GraphTraversal and __. With where(out()) going to filter(out()), ScopingStrategy is now simpler.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/167cd8d5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/167cd8d5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/167cd8d5

Branch: refs/heads/master
Commit: 167cd8d5a15c32dbe0955d1ed06a39c9ab04ca4f
Parents: 88a93ae
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon Jun 22 08:42:48 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon Jun 22 08:42:48 2015 -0600

----------------------------------------------------------------------
 .../gremlin/process/traversal/dsl/graph/GraphTraversal.java  | 8 ++++----
 .../tinkerpop/gremlin/process/traversal/dsl/graph/__.java    | 8 ++++----
 .../tinkerpop/gremlin/process/traversal/step/Scoping.java    | 2 +-
 .../gremlin/process/traversal/step/filter/WhereStep.java     | 6 +++---
 .../traversal/strategy/finalization/ScopingStrategy.java     | 6 ++----
 5 files changed, 14 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/167cd8d5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index c6c7768..25c948d 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -658,11 +658,11 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
         return this.asAdmin().addStep(scope.equals(Scope.global) ? new DedupGlobalStep<>(this.asAdmin()) : new DedupLocalStep(this.asAdmin()));
     }
 
-    public default GraphTraversal<S, E> where(final Scope scope, final String startKey, final P<?> predicate) {
+    public default GraphTraversal<S, E> where(final Scope scope, final String startKey, final P<String> predicate) {
         return this.asAdmin().addStep(new WhereStep<>(this.asAdmin(), scope, Optional.ofNullable(startKey), predicate));
     }
 
-    public default GraphTraversal<S, E> where(final Scope scope, final P<?> predicate) {
+    public default GraphTraversal<S, E> where(final Scope scope, final P<String> predicate) {
         return this.where(scope, null, predicate);
     }
 
@@ -672,11 +672,11 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
                 this.asAdmin().addStep(new WhereStep(this.asAdmin(), scope, whereTraversal));
     }
 
-    public default GraphTraversal<S, E> where(final String startKey, final P<?> predicate) {
+    public default GraphTraversal<S, E> where(final String startKey, final P<String> predicate) {
         return this.where(Scope.global, startKey, predicate);
     }
 
-    public default GraphTraversal<S, E> where(final P<?> predicate) {
+    public default GraphTraversal<S, E> where(final P<String> predicate) {
         return this.where(Scope.global, null, predicate);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/167cd8d5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
index dfafadd..ba8d592 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/__.java
@@ -567,11 +567,11 @@ public class __ {
         return __.<A>start().hasValue(values);
     }
 
-    public static <A> GraphTraversal<A, A> where(final Scope scope, final String startKey, final P<?> predicate) {
+    public static <A> GraphTraversal<A, A> where(final Scope scope, final String startKey, final P<String> predicate) {
         return __.<A>start().where(scope, startKey, predicate);
     }
 
-    public static <A> GraphTraversal<A, A> where(final Scope scope, final P<?> predicate) {
+    public static <A> GraphTraversal<A, A> where(final Scope scope, final P<String> predicate) {
         return __.<A>start().where(scope, predicate);
     }
 
@@ -579,11 +579,11 @@ public class __ {
         return __.<A>start().where(scope, whereTraversal);
     }
 
-    public static <A> GraphTraversal<A, A> where(final String startKey, final P<?> predicate) {
+    public static <A> GraphTraversal<A, A> where(final String startKey, final P<String> predicate) {
         return __.<A>start().where(startKey, predicate);
     }
 
-    public static <A> GraphTraversal<A, A> where(final P<?> predicate) {
+    public static <A> GraphTraversal<A, A> where(final P<String> predicate) {
         return __.<A>start().where(predicate);
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/167cd8d5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/Scoping.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/Scoping.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/Scoping.java
index fd96279..8f55d7e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/Scoping.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/Scoping.java
@@ -36,7 +36,7 @@ import java.util.Set;
  */
 public interface Scoping {
 
-    public static enum Variable {START, END, NONE}
+    public static enum Variable {START, END}
 
     public default <S> S getScopeValueByKey(final Pop pop, final String key, final Traverser.Admin<?> traverser) throws IllegalArgumentException {
         if (traverser.getSideEffects().get(key).isPresent())

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/167cd8d5/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 91a9b51..67ec7b4 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
@@ -57,7 +57,7 @@ public final class WhereStep<S> extends FilterStep<S> implements TraversalParent
     protected final Set<String> scopeKeys = new HashSet<>();
     protected final Set<Variable> variables = new HashSet<>();
 
-    public WhereStep(final Traversal.Admin whereTraversal, final Scope scope, final Optional<String> startKey, final P<?> predicate) {
+    public WhereStep(final Traversal.Admin whereTraversal, final Scope scope, final Optional<String> startKey, final P<String> predicate) {
         super(whereTraversal);
         this.scope = scope;
         this.startKey = startKey.orElse(null);
@@ -79,6 +79,8 @@ public final class WhereStep<S> extends FilterStep<S> implements TraversalParent
         this.predicate = null;
         this.selectKeys = null;
         this.whereTraversal = whereTraversal.asAdmin();
+        if(TraversalHelper.getVariableLocations(this.whereTraversal).isEmpty())
+            throw new IllegalArgumentException("A where()-traversal must have at least a start or end label (i.e. variable): " + whereTraversal);
         this.configureStartAndEndSteps(this.whereTraversal);
         this.whereTraversal = this.integrateChild(this.whereTraversal);
     }
@@ -98,8 +100,6 @@ public final class WhereStep<S> extends FilterStep<S> implements TraversalParent
             this.variables.add(Variable.START);
         } else if (!whereTraversal.getEndStep().getLabels().isEmpty()) {                    // ...out().as("a") traversals
             TraversalHelper.insertBeforeStep(new WhereStartStep(whereTraversal, null), (Step) startStep, whereTraversal);
-        } else {
-            this.variables.add(Variable.NONE);
         }
         //// END STEP to WhereEndStep
         final Step<?, ?> endStep = whereTraversal.getEndStep();

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/167cd8d5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/ScopingStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/ScopingStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/ScopingStrategy.java
index 88d16d6..efce9b8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/ScopingStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/ScopingStrategy.java
@@ -46,13 +46,11 @@ public final class ScopingStrategy extends AbstractTraversalStrategy<TraversalSt
         final Set<String> pathLabels = TraversalHelper.getLabels(TraversalHelper.getRootTraversal(traversal));
         traversal.getSteps().stream().forEach(step -> {
             if (step instanceof Scoping) {
-                if (step.getPreviousStep() instanceof Scoping && !((Scoping)step.getPreviousStep()).getVariableLocations().contains(Scoping.Variable.NONE))
+                if (step.getPreviousStep() instanceof Scoping)
                     ((Scoping) step).setScope(((Scoping) step.getPreviousStep()).recommendNextScope());
                 else if (Scope.global == ((Scoping) step).getScope() && step != traversal.getStartStep()) { // for Match(Where())
                     final Set<String> keys = ((Scoping) step).getScopeKeys();
-                    if(keys.isEmpty() && step instanceof WhereStep)
-                        ((Scoping) step).setScope(Scope.local);
-                    else if (!keys.isEmpty() && !((Scoping) step).getScopeKeys().stream().filter(pathLabels::contains).findAny().isPresent())
+                    if (!keys.isEmpty() && !keys.stream().filter(pathLabels::contains).findAny().isPresent())
                         ((Scoping) step).setScope(Scope.local);
                 }
             }