You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/03/27 21:55:41 UTC

[1/6] incubator-tinkerpop git commit: Make test name consistent in SubgraphStrategyProcessTest.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 0a3d63481 -> f146e49c4


Make test name consistent in SubgraphStrategyProcessTest.


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

Branch: refs/heads/master
Commit: b0c70e2fffcebe6d426dd55eeef65fb03494f226
Parents: 820a0a5
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 27 14:41:54 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 27 14:41:54 2015 -0400

----------------------------------------------------------------------
 .../traversal/strategy/decoration/SubgraphStrategyProcessTest.java | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b0c70e2f/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java
index 2ecffc3..eaf451d 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java
@@ -47,7 +47,7 @@ public class SubgraphStrategyProcessTest  extends AbstractGremlinProcessTest {
 
     @Test
     @LoadGraphWith(MODERN)
-    public void testVertexCriterion() throws Exception {
+    public void shouldFilterVertexCriterion() throws Exception {
         final Predicate<Vertex> vertexCriterion = vertex -> vertex.value("name").equals("josh") || vertex.value("name").equals("lop") || vertex.value("name").equals("ripple");
         final Predicate<Edge> edgeCriterion = edge -> true;
 


[3/6] incubator-tinkerpop git commit: Merge remote-tracking branch 'origin/master'

Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/master'


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

Branch: refs/heads/master
Commit: 8593123d57c46cc967351a36af1eaeaebfb69fac
Parents: e54d423 0a3d634
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 27 16:32:25 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 27 16:32:25 2015 -0400

----------------------------------------------------------------------
 docs/preprocessor/preprocess.sh                 |   7 +-
 .../process/computer/spark/SparkExecutor.java   | 105 +++++++++++++++----
 .../computer/spark/SparkGraphComputer.java      |   4 +-
 .../process/computer/spark/SparkMapEmitter.java |   9 +-
 .../process/computer/spark/SparkMessenger.java  |  83 +++++++++++++++
 .../computer/spark/SparkReduceEmitter.java      |   9 +-
 pom.xml                                         |   2 +-
 7 files changed, 191 insertions(+), 28 deletions(-)
----------------------------------------------------------------------



[6/6] incubator-tinkerpop git commit: Added documentation for ElementIdStrategy.

Posted by sp...@apache.org.
Added documentation for ElementIdStrategy.


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

Branch: refs/heads/master
Commit: f146e49c48e66cbe73261fb56159cf9a21454082
Parents: 09802b1
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 27 16:55:26 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 27 16:55:26 2015 -0400

----------------------------------------------------------------------
 docs/src/the-traversal.asciidoc | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f146e49c/docs/src/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-traversal.asciidoc b/docs/src/the-traversal.asciidoc
index ff746e0..bcf4d07 100644
--- a/docs/src/the-traversal.asciidoc
+++ b/docs/src/the-traversal.asciidoc
@@ -1594,6 +1594,34 @@ t.toString()
 
 TinkerPop has a number of type-3 strategies distributed as part of its core library.  These strategies add generalized features to a traversal that are typically useful to end-users.  The following sections detail these strategies:
 
+ElementIdStrategy
+=================
+
+`ElementIdStrategy` provides control over element identifiers. Some Graph implementations, such as TinkerGraph, allow specification of custom identifiers when creating elements:
+
+[gremlin-groovy]
+----
+g = TinkerGraph.open().traversal()
+v = g.addV(id,"42a")
+g.V("42a")
+----
+
+Other `Graph` implementations, such as Neo4j, generate element identifiers automatically and cannot be assigned.  As a helper, `ElementIdStrategy` can be used to make identifier assignment possible by using vertex and edge indicies under the hood.
+
+[source,groovy]
+----
+gremlin> graph = Neo4jGraph.open('/tmp/neo4j')
+==>neo4jgraph[EmbeddedGraphDatabase [/tmp/neo4j]]
+gremlin> strategy = ElementIdStrategy.build().create()
+==>ElementIdStrategy
+gremlin> g = GraphTraversalSource.build().with(strategy).create(graph)
+==>graphtraversalsource[neo4jgraph[EmbeddedGraphDatabase [/tmp/neo4j]], standard]
+gremlin> g.addV(id, "42a").id()
+==>42a
+----
+
+IMPORTANT: The key that is used to store the assigned identifier should be indexed in the underlying graph database. If it is not indexed, then lookups for the elements that use these identifiers will perform a linear scan.
+
 EventStrategy
 =============
 


[2/6] incubator-tinkerpop git commit: Built out the existing stub for `ElementIdStrategy` and added tests.

Posted by sp...@apache.org.
Built out the existing stub for  `ElementIdStrategy` and added tests.


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

Branch: refs/heads/master
Commit: e54d42339cb7e5890a2ba2a56626690b4f50a14f
Parents: b0c70e2
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 27 16:31:42 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 27 16:31:42 2015 -0400

----------------------------------------------------------------------
 .../strategy/decoration/ElementIdStrategy.java  | 105 +++++++++++-
 .../gremlin/structure/util/ElementHelper.java   |  13 ++
 .../ElementIdStrategyTraverseTest.java          | 110 +++++++++++++
 .../gremlin/process/ProcessStandardSuite.java   |   2 +
 .../ElementIdStrategyProcessTest.java           | 161 +++++++++++++++++++
 5 files changed, 385 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e54d4233/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
index 81d78be..ec47787 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategy.java
@@ -22,14 +22,28 @@ import org.apache.tinkerpop.gremlin.process.traversal.T;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeByPathStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStartStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.IdStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertyElementStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertyValueStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GraphStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 import org.apache.tinkerpop.gremlin.structure.Contains;
+import org.apache.tinkerpop.gremlin.structure.Element;
+import org.apache.tinkerpop.gremlin.structure.PropertyType;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
 import java.util.Arrays;
+import java.util.UUID;
+import java.util.function.Supplier;
+import java.util.stream.Stream;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -38,8 +52,19 @@ public final class ElementIdStrategy extends AbstractTraversalStrategy {
 
     private final String idPropertyKey;
 
-    public ElementIdStrategy(final String idPropertyKey) {
+    private final Supplier<Object> idMaker;
+
+    private ElementIdStrategy(final String idPropertyKey, final Supplier<Object> idMaker) {
         this.idPropertyKey = idPropertyKey;
+        this.idMaker = idMaker;
+    }
+
+    public String getIdPropertyKey() {
+        return idPropertyKey;
+    }
+
+    public Supplier<Object> getIdMaker() {
+        return idMaker;
     }
 
     @Override
@@ -50,18 +75,86 @@ public final class ElementIdStrategy extends AbstractTraversalStrategy {
 
         if (traversal.getStartStep() instanceof GraphStep) {
             final GraphStep graphStep = (GraphStep) traversal.getStartStep();
-            if (graphStep instanceof HasContainerHolder)
-                ((HasContainerHolder) graphStep).addHasContainer(new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds())));
-            else
-                TraversalHelper.insertAfterStep(new HasStep(traversal, new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds()))), graphStep, traversal);
-            graphStep.clearIds();
+
+            // only need to apply the custom id if ids were assigned - otherwise we want the full iterator.
+            // note that it is then only necessary to replace the step if the id is a non-element.  other tests
+            // in the suite validate that items in getIds() is uniform so it is ok to just test the first item
+            // in the list.
+            if (graphStep.getIds().length > 0) {
+                if (graphStep instanceof HasContainerHolder) {
+                    if (!(graphStep.getIds()[0] instanceof Element))
+                        ((HasContainerHolder) graphStep).addHasContainer(new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds())));
+                } else {
+                    if (!(graphStep.getIds()[0] instanceof Element))
+                        TraversalHelper.insertAfterStep(new HasStep(traversal, new HasContainer(this.idPropertyKey, Contains.within, Arrays.asList(graphStep.getIds()))), graphStep, traversal);
+                }
+                graphStep.clearIds();
+            }
         }
 
+        TraversalHelper.getStepsOfAssignableClass(IdStep.class, traversal).stream().forEach(s -> {
+            TraversalHelper.replaceStep(s, new PropertiesStep(traversal, PropertyType.VALUE, idPropertyKey), traversal);
+        });
+
+        // in each case below, determine if the T.id is present and if so, replace T.id with the idPropertyKey or if
+        // it is not present then shove it in there and generate an id
+        TraversalHelper.getStepsOfAssignableClass(AddVertexStep.class, traversal).stream().forEach(s -> {
+            if (ElementHelper.getIdValue(s.getKeyValues()).isPresent())
+                TraversalHelper.replaceStep(s, new AddVertexStep(traversal, ElementHelper.replaceKey(s.getKeyValues(), T.id, idPropertyKey)), traversal);
+            else
+                TraversalHelper.replaceStep(s, new AddVertexStep(traversal, ElementHelper.upsert(s.getKeyValues(), idPropertyKey, idMaker.get())), traversal);
+        });
+
+        TraversalHelper.getStepsOfAssignableClass(AddVertexStartStep.class, traversal).stream().forEach(s -> {
+            if (ElementHelper.getIdValue(s.getKeyValues()).isPresent())
+                TraversalHelper.replaceStep(s, new AddVertexStartStep(traversal, ElementHelper.replaceKey(s.getKeyValues(), T.id, idPropertyKey)), traversal);
+            else
+                TraversalHelper.replaceStep(s, new AddVertexStartStep(traversal, ElementHelper.upsert(s.getKeyValues(), idPropertyKey, idMaker.get())), traversal);
+        });
+
+        TraversalHelper.getStepsOfAssignableClass(AddEdgeStep.class, traversal).stream().forEach(s -> {
+            if (ElementHelper.getIdValue(s.getKeyValues()).isPresent())
+                TraversalHelper.replaceStep(s, new AddEdgeStep(traversal, s.getDirection(), s.getEdgeLabel(), s.getVertices().iterator(), ElementHelper.replaceKey(s.getKeyValues(), T.id, idPropertyKey)), traversal);
+            else
+                TraversalHelper.replaceStep(s, new AddEdgeStep(traversal, s.getDirection(), s.getEdgeLabel(), s.getVertices().iterator(), ElementHelper.upsert(s.getKeyValues(), idPropertyKey, idMaker.get())), traversal);
+        });
+
+        TraversalHelper.getStepsOfAssignableClass(AddEdgeByPathStep.class, traversal).stream().forEach(s -> {
+            if (ElementHelper.getIdValue(s.getKeyValues()).isPresent())
+                TraversalHelper.replaceStep(s, new AddEdgeByPathStep(traversal, s.getDirection(), s.getEdgeLabel(), s.getStepLabel(), ElementHelper.replaceKey(s.getKeyValues(), T.id, idPropertyKey)), traversal);
+            else
+                TraversalHelper.replaceStep(s, new AddEdgeByPathStep(traversal, s.getDirection(), s.getEdgeLabel(), s.getStepLabel(), ElementHelper.upsert(s.getKeyValues(), idPropertyKey, idMaker.get())), traversal);
+        });
+    }
 
+    public static Builder build() {
+        return new Builder();
     }
 
     @Override
     public String toString() {
         return StringFactory.traversalStrategyString(this);
     }
+
+    public static class Builder {
+        private String idPropertyKey = "__id";
+
+        private Supplier<Object> idMaker = () -> UUID.randomUUID().toString();
+
+        private Builder() {}
+
+        public Builder idMaker(final Supplier<Object> idMaker) {
+            this.idMaker = idMaker;
+            return this;
+        }
+
+        public Builder idPropertyKey(final String idPropertyKey) {
+            this.idPropertyKey = idPropertyKey;
+            return this;
+        }
+
+        public ElementIdStrategy create() {
+            return new ElementIdStrategy(idPropertyKey, idMaker);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e54d4233/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
index 7e91edf..94d4a5b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/ElementHelper.java
@@ -182,6 +182,19 @@ public final class ElementHelper {
         }
     }
 
+    public static Object[] replaceKey(final Object[] keyValues, final Object oldKey, final Object newKey) {
+        final Object[] kvs = new Object[keyValues.length];
+        for (int i = 0; i < keyValues.length; i = i + 2) {
+            if (keyValues[i].equals(oldKey))
+                kvs[i] = newKey;
+            else
+                kvs[i] = keyValues[i];
+            kvs[i + 1] = keyValues[i + 1];
+        }
+
+        return kvs;
+    }
+
     /**
      * Converts a set of key values to a Map.  Assumes that validations have already taken place to
      * assure that key positions contain strings and that there are an even number of elements.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e54d4233/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategyTraverseTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategyTraverseTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategyTraverseTest.java
new file mode 100644
index 0000000..75dca11
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategyTraverseTest.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Step;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeByPathStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStartStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.AddVertexStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GraphStep;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.Arrays;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@RunWith(Parameterized.class)
+public class ElementIdStrategyTraverseTest {
+    private static Traversal traversalWithAddV;
+
+    static {
+        final Graph mockedGraph = mock(Graph.class);
+        final DefaultGraphTraversal t = new DefaultGraphTraversal<>(mockedGraph);
+        t.asAdmin().addStep(new GraphStep<>(t.asAdmin(), Vertex.class));
+        traversalWithAddV = t.addV();
+    }
+
+    @Parameterized.Parameters(name = "{0}")
+    public static Iterable<Object[]> data() {
+        return Arrays.asList(new Object[][]{
+                {"addV()", traversalWithAddV, 1},
+                {"addInE()", __.addInE("test", "x"), 0},
+                {"addOutE()", __.addOutE("test", "x"), 0},
+                {"addInE()", __.addInE("test", "x", "other", "args"), 0},
+                {"addOutE()", __.addOutE("test", "x", "other", "args"), 0},
+                {"addE(OUT)", __.addE(Direction.OUT, "test", "x"), 0},
+                {"addE(IN)", __.addE(Direction.IN, "test", "x"), 0},
+                {"out().id()", __.out().id(), 1},
+                {"in().id()", __.in().id(), 1},
+                {"outE().id()", __.outE().id(), 1},
+                {"inE().id()", __.inE().id(), 1},
+                {"bothE().id()", __.bothE().id(), 1},
+                {"bothE().otherV().id()", __.bothE().otherV().id(), 2},
+                {"in().out().addInE()", __.in().out().addInE("test", "x"), 2},
+                {"in().out().addOutE()", __.in().out().addOutE("test", "x"), 2},
+                {"in().out().addE(OUT)", __.in().out().addE(Direction.OUT, "test", "x"), 2},
+                {"in().out().addE(IN)", __.in().out().addE(Direction.IN, "test", "x"), 2}});
+    }
+
+    @Parameterized.Parameter(value = 0)
+    public String name;
+
+    @Parameterized.Parameter(value = 1)
+    public Traversal traversal;
+
+    @Parameterized.Parameter(value = 2)
+    public int expectedInsertedSteps;
+
+    @Test
+    public void shouldAlterTraversalToIncludeIdWhereNecessary() {
+        final ElementIdStrategy strategy = ElementIdStrategy.build().create();
+        strategy.apply(traversal.asAdmin());
+
+        final Step s = (Step) traversal.asAdmin().getSteps().get(expectedInsertedSteps);
+        if(s instanceof AddVertexStep)
+            assertTrue(ElementHelper.getKeys(((AddVertexStep) s).getKeyValues()).contains(strategy.getIdPropertyKey()));
+        else if(s instanceof AddVertexStartStep)
+            assertTrue(ElementHelper.getKeys(((AddVertexStartStep) s).getKeyValues()).contains(strategy.getIdPropertyKey()));
+        else if(s instanceof AddEdgeByPathStep)
+            assertTrue(ElementHelper.getKeys(((AddEdgeByPathStep) s).getKeyValues()).contains(strategy.getIdPropertyKey()));
+        else if(s instanceof AddEdgeStep)
+            assertTrue(ElementHelper.getKeys(((AddEdgeStep) s).getKeyValues()).contains(strategy.getIdPropertyKey()));
+        else if(s instanceof PropertiesStep)
+            assertEquals(strategy.getIdPropertyKey(), ((PropertiesStep) s).getPropertyKeys()[0]);
+        else
+            fail("Check test definition - the expectedInsertedSteps should be the index of the step to trigger the ID substitution");
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e54d4233/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
index 72d92b0..c2af8e7 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
@@ -74,6 +74,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.StoreTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SubgraphTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.TreeTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.PathTest;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategyProcessTest;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategyProcessTest;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategyProcessTest;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategyProcessTest;
@@ -192,6 +193,7 @@ public class ProcessStandardSuite extends AbstractGremlinSuite {
             // PageRankVertexProgramTest.class
 
             // decorations
+            ElementIdStrategyProcessTest.class,
             EventStrategyProcessTest.class,
             ReadOnlyStrategyProcessTest.class,
             PartitionStrategyProcessTest.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e54d4233/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategyProcessTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategyProcessTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategyProcessTest.java
new file mode 100644
index 0000000..1296164
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/ElementIdStrategyProcessTest.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration;
+
+import org.apache.tinkerpop.gremlin.FeatureRequirementSet;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.UseEngine;
+import org.apache.tinkerpop.gremlin.process.traversal.T;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.junit.Test;
+
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@UseEngine(TraversalEngine.Type.STANDARD)
+public class ElementIdStrategyProcessTest extends AbstractGremlinProcessTest {
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldGenerateDefaultIdOnGraphAddVWithGeneratedDefaultId() throws Exception {
+        final ElementIdStrategy strategy = ElementIdStrategy.build().create();
+        final GraphTraversalSource sg = create(strategy);
+        final Vertex v = sg.addV("name", "stephen").next();
+        assertEquals("stephen", v.value("name"));
+
+        final Traversal t1 = graph.traversal().V(v);
+        t1.asAdmin().applyStrategies();
+        System.out.println(t1);
+
+        final Traversal t2 = sg.V(v);
+        t2.asAdmin().applyStrategies();
+        System.out.println(t2);
+
+        assertNotNull(UUID.fromString(sg.V(v).id().next().toString()));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldGenerateDefaultIdOnGraphAddVWithGeneratedCustomId() throws Exception {
+        final ElementIdStrategy strategy = ElementIdStrategy.build().idMaker(() -> "xxx").create();
+        final GraphTraversalSource sg = create(strategy);
+        final Vertex v = sg.addV("name", "stephen").next();
+        assertEquals("stephen", v.value("name"));
+        assertEquals("xxx", sg.V(v).id().next());
+        assertEquals("xxx", sg.V("xxx").id().next());
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldGenerateDefaultIdOnGraphAddVWithSpecifiedId() throws Exception {
+        final ElementIdStrategy strategy = ElementIdStrategy.build().create();
+        final GraphTraversalSource sg = create(strategy);
+        final Vertex v = sg.addV(T.id, "STEPHEN", "name", "stephen").next();
+        assertEquals("stephen", v.value("name"));
+        assertEquals("STEPHEN", sg.V(v).id().next());
+        assertEquals("STEPHEN", sg.V("STEPHEN").id().next());
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldGenerateDefaultIdOnAddVWithGeneratedDefaultId() throws Exception {
+        final ElementIdStrategy strategy = ElementIdStrategy.build().create();
+        final GraphTraversalSource sg = create(strategy);
+        sg.addV().next();
+        assertEquals(1, IteratorUtils.count(sg.V()));
+
+        final Vertex v = sg.V().addV("name", "stephen").next();
+        assertEquals("stephen", v.value("name"));
+        assertNotNull(UUID.fromString(sg.V(v).id().next().toString()));
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldGenerateDefaultIdOnAddVWithGeneratedCustomId() throws Exception {
+        final AtomicBoolean first = new AtomicBoolean(false);
+        final ElementIdStrategy strategy = ElementIdStrategy.build().idMaker(() -> {
+            final String key = first.get() ? "xxx" : "yyy";
+            first.set(true);
+            return key;
+        }).create();
+        final GraphTraversalSource sg = create(strategy);
+        sg.addV().next();
+        assertEquals(1, IteratorUtils.count(sg.V()));
+
+        final Vertex v = sg.V().addV("name", "stephen").next();
+        assertEquals("stephen", v.value("name"));
+        assertEquals("xxx", sg.V(v).id().next());
+        assertEquals("xxx", sg.V("xxx").id().next());
+        assertEquals("yyy", sg.V("yyy").id().next());
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.VERTICES_ONLY)
+    public void shouldGenerateDefaultIdOnAddVWithSpecifiedId() throws Exception {
+        final ElementIdStrategy strategy = ElementIdStrategy.build().create();
+        final GraphTraversalSource sg = create(strategy);
+        sg.addV().next();
+        assertEquals(1, IteratorUtils.count(sg.V()));
+
+        final Vertex v = sg.V().addV(T.id, "STEPHEN", "name", "stephen").next();
+        assertEquals("stephen", v.value("name"));
+        assertEquals("STEPHEN", sg.V(v).id().next());
+        assertEquals("STEPHEN", sg.V("STEPHEN").id().next());
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldGenerateDefaultIdOnAddEWithSpecifiedId() throws Exception {
+        final ElementIdStrategy strategy = ElementIdStrategy.build().create();
+        final GraphTraversalSource sg = create(strategy);
+        final Vertex v = sg.addV().next();
+        final Edge e = sg.V(v).addE(Direction.OUT, "self", v, "test", "value", T.id, "some-id").next();
+        assertEquals("value", e.value("test"));
+        assertEquals("some-id", sg.E(e).id().next());
+        assertEquals("some-id", sg.E("some-id").id().next());
+    }
+
+    @Test
+    @FeatureRequirementSet(FeatureRequirementSet.Package.SIMPLE)
+    public void shouldGenerateDefaultIdOnAddEWithGeneratedId() throws Exception {
+        final ElementIdStrategy strategy = ElementIdStrategy.build().create();
+        final GraphTraversalSource sg = create(strategy);
+        final Vertex v = sg.addV().next();
+        final Edge e = sg.V(v).addE(Direction.OUT, "self", v, "test", "value").next();
+        assertEquals("value", e.value("test"));
+        assertNotNull(UUID.fromString(sg.E(e).id().next().toString()));
+    }
+
+    private GraphTraversalSource create(final ElementIdStrategy strategy) {
+        return graphProvider.traversal(graph, strategy);
+    }
+}


[4/6] incubator-tinkerpop git commit: Add docs for SubgraphStrategy.

Posted by sp...@apache.org.
Add docs for SubgraphStrategy.


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

Branch: refs/heads/master
Commit: 195488798f523f852df545dbf539001a9d951971
Parents: 8593123
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 27 16:39:05 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 27 16:39:05 2015 -0400

----------------------------------------------------------------------
 docs/src/the-traversal.asciidoc | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/19548879/docs/src/the-traversal.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/the-traversal.asciidoc b/docs/src/the-traversal.asciidoc
index a517f23..ff746e0 100644
--- a/docs/src/the-traversal.asciidoc
+++ b/docs/src/the-traversal.asciidoc
@@ -1661,6 +1661,24 @@ ReadOnlyStrategy
 
 `ReadOnlyStrategy` is largely self-explanatory.  A `Traversal` that has this strategy applied will throw an `IllegalStateException` if the `Traversal` has any mutating steps within it.
 
+SubgraphStrategy
+================
+
+`SubgraphStrategy` is quite similar to `PartitionStrategy` in that it restrains a `Traversal` to certain vertices and edges as determined by a `Predicate` defined individually for each.
+
+[gremlin-groovy]
+----
+graph = TinkerFactory.createModern()
+vertexCriterion = { vertex -> true }
+edgeCriterion = { edge -> (int) edge.id() >= 8 && (int) edge.id() <= 10}
+strategy = SubgraphStrategy.build().vertexPredicate(vertexCriterion).edgePredicate(edgeCriterion).create()
+g = GraphTraversalSource.build().with(strategy).create(graph)
+g.V() //// shows all vertices as they all pass the vertexCriterion
+g.E() //// shows only the edges defined in the edgeCriterion
+----
+
+Note that `SubgraphStrategy` directly passes the edge and vertex criterion `Predicate` objects  to an injected `filter` step and as such may not take advantage of important optimizations provided by the various `Graph` implementations (given the use of lambda expressions).
+
 Domain Specific Languages
 -------------------------
 


[5/6] incubator-tinkerpop git commit: Update changelog.

Posted by sp...@apache.org.
Update changelog.


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

Branch: refs/heads/master
Commit: 09802b1386d6d0dbb75b80a811ac0acd8759979d
Parents: 1954887
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Mar 27 16:50:04 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Mar 27 16:50:04 2015 -0400

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/09802b13/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index bd1ae66..75f45a3 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ TinkerPop 3.0.0.M8 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 * `Vertex.property()` default behavior is now `Cardinality.single`.
+* Added `ElementIdStrategy` as a `TraversalStrategy`.
 * Introduce `AbstractTransaction` to simplify implementation of standard transactional features for vendors.
 * Added `EventStrategy` to generate `Graph` modification events to listeners.
 * Added test to enforce return of an empty `Property` on `VertexProperty.property(k)` if no meta properties exist.