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/08/28 17:55:34 UTC

incubator-tinkerpop git commit: Add better support for PartitionStrategy on VertexProperty.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP3-333 728ca2fbd -> d74fc5dbd


Add better support for PartitionStrategy on VertexProperty.

The strategy injects choose() steps to dynamically detect Vertex/VertexProperty access as this information is not known from a static traversal. It is only known at runtime.


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

Branch: refs/heads/TINKERPOP3-333
Commit: d74fc5dbd124e2aa7679a3db6f06f52e0a8df886
Parents: 728ca2f
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Fri Aug 28 11:54:10 2015 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Fri Aug 28 11:54:10 2015 -0400

----------------------------------------------------------------------
 .../strategy/decoration/PartitionStrategy.java  | 31 +++++++++++++-------
 .../PartitionStrategyProcessTest.java           |  2 +-
 2 files changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d74fc5db/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
index 8e7ebf0..c79fa17 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Parameterizing;
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Mutating;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep;
@@ -117,17 +118,27 @@ public final class PartitionStrategy extends AbstractTraversalStrategy<Traversal
             final List<PropertiesStep> propertiesSteps = TraversalHelper.getStepsOfAssignableClass(PropertiesStep.class, traversal);
             propertiesSteps.forEach(step -> {
                 if (step.getReturnType() == PropertyType.PROPERTY) {
-                    // this is the same filter application as above for the other steps
-                    TraversalHelper.insertAfterStep(
-                            new HasStep(traversal, new HasContainer(partitionKey, P.within(new ArrayList<>(readPartitions)))), step, traversal);
+                    // check the following step to see if it is a has(partitionKey, *) - if so then this strategy was
+                    // already applied down below via g.V().values() which injects a properties() step
+                    final Step next = step.getNextStep();
+                    if (!(next instanceof HasStep) || !((HasContainer) ((HasStep) next).getHasContainers().get(0)).getKey().equals(partitionKey)) {
+                        // use choose() to determine if the properties() step is called on a Vertex to get a VertexProperty
+                        // if not, pass it through.
+                        final Traversal choose = __.choose(
+                                __.filter(e -> e.get() instanceof VertexProperty),
+                                __.has(partitionKey, P.within(new ArrayList<>(readPartitions))),
+                                __.__());
+                        TraversalHelper.insertTraversal(step, choose.asAdmin(), traversal);
+                    }
                 } else if (step.getReturnType() == PropertyType.VALUE) {
-                    // explode g.V().values() to g.V().property().has().value()
-                    final PropertiesStep propertiesStep = new PropertiesStep(traversal, PropertyType.PROPERTY, step.getPropertyKeys());
-                    final HasStep hasStep = new HasStep(traversal, new HasContainer(partitionKey, P.within(new ArrayList<>(readPartitions))));
-                    final PropertyValueStep valueStep = new PropertyValueStep(traversal);
-                    TraversalHelper.replaceStep(step, propertiesStep, traversal);
-                    TraversalHelper.insertAfterStep(hasStep, propertiesStep, traversal);
-                    TraversalHelper.insertAfterStep(valueStep, hasStep, traversal);
+                    // use choose() to determine if the values() step is called on a Vertex to get a VertexProperty
+                    // if not, pass it through otherwise explode g.V().values() to g.V().properties().has().value()
+                    final Traversal choose = __.choose(
+                            __.filter(e -> e.get() instanceof Vertex),
+                            __.properties(step.getPropertyKeys()).has(partitionKey, P.within(new ArrayList<>(readPartitions))).value(),
+                            __.__());
+                    TraversalHelper.insertTraversal(step, choose.asAdmin(), traversal);
+                    traversal.removeStep(step);
                 } else {
                     throw new IllegalStateException(String.format("%s is not accounting for a particular PropertyType %s",
                             PartitionStrategy.class.getSimpleName(), step.getReturnType()));

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d74fc5db/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
index cfbc86c..520d9d9 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
@@ -123,7 +123,7 @@ public class PartitionStrategyProcessTest extends AbstractGremlinProcessTest {
         assertThat(gOverB.V(v).values("any").hasNext(), is(false));
         assertThat(gOverB.V(v).values("that").hasNext(), is(false));
 
-        assertThat(gOverAB.V(v).valueMap("any").hasNext(), is(true));
+        assertThat(gOverAB.V(v).values("any").hasNext(), is(true));
         assertThat(gOverAB.V(v).values("that").hasNext(), is(true));
         assertThat(gOverA.V(v).values("that").hasNext(), is(false));
         assertThat(gOverA.V(v).values("any").hasNext(), is(true));