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/12 01:21:07 UTC
incubator-tinkerpop git commit: XMatchStep getting reeeeeaaaalll
basic. Added comments to explain what the different parts of the step are
doing. Lots of code clean up.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/xmatch d088202d6 -> 28a4f7ae4
XMatchStep getting reeeeeaaaalll basic. Added comments to explain what the different parts of the step are doing. Lots of code clean up.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/28a4f7ae
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/28a4f7ae
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/28a4f7ae
Branch: refs/heads/xmatch
Commit: 28a4f7ae49386b78049c06c3f5bb552f79bab00f
Parents: d088202
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Jun 11 17:20:59 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Jun 11 17:20:59 2015 -0600
----------------------------------------------------------------------
.../traversal/step/filter/exp/XMatchStep.java | 44 ++++++++++----------
.../tinkergraph/structure/TinkerGraphTest.java | 11 +++--
2 files changed, 30 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/28a4f7ae/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 5f0c9e5..439b94c 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
@@ -54,10 +54,8 @@ 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();
-
public XMatchStep(final Traversal.Admin traversal, final Traversal... andTraversals) {
super(traversal);
for (final Traversal andTraversal : andTraversals) {
@@ -92,7 +90,6 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
return this.matchStartLabels;
}
-
public List<Traversal.Admin<Object, Object>> getGlobalChildren() {
return Collections.unmodifiableList(this.andTraversals);
}
@@ -122,24 +119,29 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
@Override
protected Iterator<Traverser<S>> standardAlgorithm() throws NoSuchElementException {
while (true) {
+ Traverser.Admin traverser = null;
if (this.first) {
this.matchAlgorithm.initialize(this.andTraversals);
this.first = false;
} else {
for (final Traversal.Admin<?, ?> andTraversal : this.andTraversals) {
- if (andTraversal.hasNext())
- this.starts.add((Traverser.Admin) andTraversal.getEndStep().next().asAdmin());
+ if (andTraversal.hasNext()) {
+ traverser = andTraversal.getEndStep().next().asAdmin();
+ break;
+ }
}
}
- final Traverser.Admin traverser = this.starts.next();
- final Optional<Traversal.Admin<Object, Object>> optional = this.matchAlgorithm.apply(traverser);
+ if (null == traverser) traverser = this.starts.next();
+ final Optional<Traversal.Admin<Object, Object>> optional = this.matchAlgorithm.apply(traverser); // determine which sub-pattern the traverser should try next
if (optional.isPresent()) {
final Traversal.Admin<Object, Object> traversal = optional.get();
- traverser.path().addLabel(traversal.getStartStep().getId());
- traversal.addStart(traverser);
+ traverser.path().addLabel(traversal.getStartStep().getId()); // unique identifier for the traversal match sub-pattern
+ traversal.addStart(traverser); // go down the traversal match sub-pattern
} else
// TODO: trim off internal traversal labels from path
- return IteratorUtils.of(traverser);
+ // TODO: simply iterate through traversals.startStep.getId() and remove those labels
+ // TODO: however, they are globally unique so it might not be necessary especially if we return Map<String,Object>
+ return IteratorUtils.of(traverser); // the traverser has survived all requisite match patterns and is ready to move onto the next step
}
}
@@ -150,16 +152,18 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
this.first = false;
}
final Traverser.Admin traverser = this.starts.next();
- final Optional<Traversal.Admin<Object, Object>> optional = this.matchAlgorithm.apply(traverser);
+ final Optional<Traversal.Admin<Object, Object>> optional = this.matchAlgorithm.apply(traverser); // determine which sub-pattern the traverser should try next
if (optional.isPresent()) {
final Traversal.Admin<Object, Object> traversal = optional.get();
- traverser.path().addLabel(traversal.getStartStep().getId());
- traverser.setStepId(traversal.getStartStep().getId());
+ traverser.path().addLabel(traversal.getStartStep().getId()); // unique identifier for the traversal match sub-pattern
+ traverser.setStepId(traversal.getStartStep().getId()); // go down the traversal match sub-pattern
return IteratorUtils.of(traverser);
} else {
// TODO: trim off internal traversal labels from path
+ // TODO: simply iterate through traversals.startStep.getId() and remove those labels
+ // TODO: however, they are globally unique so it might not be necessary especially if we return Map<String,Object>
traverser.asAdmin().setStepId(this.getNextStep().getId());
- return IteratorUtils.of(traverser);
+ return IteratorUtils.of(traverser); // the traverser has survived all requisite match patterns and is ready to move onto the next step
}
}
@@ -200,12 +204,10 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
return start;
}
// path check
- else {
- final Path path = start.path();
- if (!path.hasLabel(this.matchKey) || start.get().equals(path.getSingle(Pop.head, this.matchKey))) {
- if (this.traverserStepIdSetByChild) start.setStepId(XMatchStep.this.getId());
- return start;
- }
+ final Path path = start.path();
+ if (!path.hasLabel(this.matchKey) || start.get().equals(path.getSingle(Pop.head, this.matchKey))) {
+ if (this.traverserStepIdSetByChild) start.setStepId(XMatchStep.this.getId());
+ return start;
}
}
}
@@ -238,7 +240,7 @@ public final class XMatchStep<S> extends ComputerAwareStep<S, S> implements Trav
@Override
public void initialize(final List<Traversal.Admin<Object, Object>> traversals) {
this.traversals = traversals;
- for (final Traversal.Admin<Object, Object> traversal : traversals) {
+ for (final Traversal.Admin<Object, Object> traversal : this.traversals) {
this.traversalLabels.add(traversal.getStartStep().getId());
this.startLabels.add(MatchAlgorithm.getStartLabels(traversal));
}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/28a4f7ae/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
index 8dd202f..ab53730 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphTest.java
@@ -23,7 +23,10 @@ import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
-import org.apache.tinkerpop.gremlin.structure.*;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLIo;
import org.junit.Ignore;
import org.junit.Test;
@@ -33,8 +36,8 @@ import java.util.List;
import java.util.Set;
import java.util.function.Supplier;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.neq;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*;
-import static org.apache.tinkerpop.gremlin.process.traversal.P.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -162,8 +165,8 @@ public class TinkerGraphTest {
as("b").out("created").as("c"),
as("c").in("created").as("d"),
as("d").where(neq("a")).where(neq("b")),
- as("b").out("created").has("name","ripple")
- ).select(Pop.head,"a","b","c","d").by("name").forEachRemaining(System.out::println);
+ as("b").out("created").has("name", "ripple"))
+ .select(Pop.head, "a", "b", "c", "d").forEachRemaining(System.out::println);
}
@Test