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/16 00:08:12 UTC

[11/31] incubator-tinkerpop git commit: staging for nested and/or in XMatchStep -- if a ConjunctionP is provided then it is turned into an 'Or'MatchStep or an 'And'MatchStep. Thus, its just a matter of nesting traversals as easy as that. However, I added

staging for nested and/or in XMatchStep -- if a ConjunctionP is provided then it is turned into an 'Or'MatchStep or an 'And'MatchStep. Thus, its just a matter of nesting traversals as easy as that. However, I added MatchAlgorithm.getMatchStartLabels(). If the start step of a traversal is a XMatchStep, then get all the start labels in the match.


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

Branch: refs/heads/master
Commit: d088202d66ccb21ebd52a7b06399b9434d044162
Parents: 04d9bd4
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Jun 11 17:08:24 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Jun 11 17:08:24 2015 -0600

----------------------------------------------------------------------
 .../traversal/step/filter/exp/XMatchStep.java   | 30 ++++++++++++++++++--
 1 file changed, 27 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d088202d/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java
index 799c8d3..5f0c9e5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/exp/XMatchStep.java
@@ -38,6 +38,7 @@ import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.NoSuchElementException;
@@ -52,6 +53,7 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
 
     private List<Traversal.Admin<Object, Object>> andTraversals = new ArrayList<>();
     private boolean first = true;
+    private Set<String> matchStartLabels = null;
 
     private final MatchAlgorithm matchAlgorithm = new GreedyMatchAlgorithm();
 
@@ -79,6 +81,17 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
         }
     }
 
+    public Set<String> getMatchStartLabels() {
+        if (null == this.matchStartLabels) {
+            this.matchStartLabels = new HashSet<>();
+            for (final Traversal.Admin<Object, Object> andTraversal : this.andTraversals) {
+                this.matchStartLabels.addAll(andTraversal.getStartStep().getLabels());
+            }
+            this.matchStartLabels = Collections.unmodifiableSet(this.matchStartLabels);
+        }
+        return this.matchStartLabels;
+    }
+
 
     public List<Traversal.Admin<Object, Object>> getGlobalChildren() {
         return Collections.unmodifiableList(this.andTraversals);
@@ -202,6 +215,17 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
     //////////////////////////////
 
     public interface MatchAlgorithm extends Function<Traverser.Admin<Object>, Optional<Traversal.Admin<Object, Object>>> {
+
+        public static Set<String> getStartLabels(final Traversal.Admin<Object, Object> traversal) {
+            final Step<?, ?> startStep = traversal.getStartStep();
+            if (startStep instanceof XMatchStep)
+                return ((XMatchStep) startStep).getMatchStartLabels();
+            else if (startStep instanceof SelectOneStep)
+                return ((SelectOneStep) startStep).getScopeKeys();
+            else
+                return Collections.emptySet();
+        }
+
         public void initialize(final List<Traversal.Admin<Object, Object>> traversals);
     }
 
@@ -209,14 +233,14 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
 
         private List<Traversal.Admin<Object, Object>> traversals;
         private List<String> traversalLabels = new ArrayList<>();
-        private List<String> startLabels = new ArrayList<>();
+        private List<Set<String>> startLabels = new ArrayList<>();
 
         @Override
         public void initialize(final List<Traversal.Admin<Object, Object>> traversals) {
             this.traversals = traversals;
             for (final Traversal.Admin<Object, Object> traversal : traversals) {
                 this.traversalLabels.add(traversal.getStartStep().getId());
-                this.startLabels.add(((SelectOneStep<?, ?>) traversal.getStartStep()).getScopeKeys().iterator().next());
+                this.startLabels.add(MatchAlgorithm.getStartLabels(traversal));
             }
         }
 
@@ -224,7 +248,7 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
         public Optional<Traversal.Admin<Object, Object>> apply(final Traverser.Admin<Object> traverser) {
             final Path path = traverser.path();
             for (int i = 0; i < this.traversals.size(); i++) {
-                if (path.hasLabel(this.startLabels.get(i)) && !path.hasLabel(this.traversalLabels.get(i))) {
+                if (this.startLabels.get(i).stream().filter(path::hasLabel).findAny().isPresent() && !path.hasLabel(this.traversalLabels.get(i))) {
                     return Optional.of(this.traversals.get(i));
                 }
             }