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/30 20:56:03 UTC

incubator-tinkerpop git commit: added a TinkerGraphStepStrategyTest to ensure that HasContainers are folded correctly.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 4624d1341 -> 73cf52847


added a TinkerGraphStepStrategyTest to ensure that HasContainers are folded correctly.


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

Branch: refs/heads/master
Commit: 73cf52847db5332ec270a7e32f0b88a41b92c4d1
Parents: 4624d13
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 30 12:56:08 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 30 12:56:08 2015 -0600

----------------------------------------------------------------------
 .../optimization/Neo4jGraphStepStrategy.java    | 12 ++--
 .../optimization/TinkerGraphStepStrategy.java   | 12 ++--
 .../TinkerGraphStepStrategyTest.java            | 71 ++++++++++++++++++++
 3 files changed, 79 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/73cf5284/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/strategy/optimization/Neo4jGraphStepStrategy.java
----------------------------------------------------------------------
diff --git a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/strategy/optimization/Neo4jGraphStepStrategy.java b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/strategy/optimization/Neo4jGraphStepStrategy.java
index eb98825..2337784 100644
--- a/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/strategy/optimization/Neo4jGraphStepStrategy.java
+++ b/neo4j-gremlin/src/main/java/org/apache/tinkerpop/gremlin/neo4j/process/traversal/strategy/optimization/Neo4jGraphStepStrategy.java
@@ -50,14 +50,10 @@ public final class Neo4jGraphStepStrategy extends AbstractTraversalStrategy<Trav
             TraversalHelper.replaceStep(startStep, (Step) neo4jGraphStep, traversal);
 
             Step<?, ?> currentStep = neo4jGraphStep.getNextStep();
-            while (true) {
-                if (currentStep instanceof HasContainerHolder) {
-                    neo4jGraphStep.hasContainers.addAll(((HasContainerHolder) currentStep).getHasContainers());
-                    currentStep.getLabels().forEach(neo4jGraphStep::addLabel);
-                    traversal.removeStep(currentStep);
-                } else {
-                    break;
-                }
+            while (currentStep instanceof HasContainerHolder) {
+                neo4jGraphStep.hasContainers.addAll(((HasContainerHolder) currentStep).getHasContainers());
+                currentStep.getLabels().forEach(neo4jGraphStep::addLabel);
+                traversal.removeStep(currentStep);
                 currentStep = currentStep.getNextStep();
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/73cf5284/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphStepStrategy.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphStepStrategy.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphStepStrategy.java
index 024b61c..dedec62 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphStepStrategy.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphStepStrategy.java
@@ -49,14 +49,10 @@ public final class TinkerGraphStepStrategy extends AbstractTraversalStrategy<Tra
             TraversalHelper.replaceStep(startStep, (Step) tinkerGraphStep, traversal);
 
             Step<?, ?> currentStep = tinkerGraphStep.getNextStep();
-            while (true) {
-                if (currentStep instanceof HasContainerHolder) {
-                    tinkerGraphStep.hasContainers.addAll(((HasContainerHolder) currentStep).getHasContainers());
-                    currentStep.getLabels().forEach(tinkerGraphStep::addLabel);
-                    traversal.removeStep(currentStep);
-                } else {
-                    break;
-                }
+            while (currentStep instanceof HasContainerHolder) {
+                tinkerGraphStep.hasContainers.addAll(((HasContainerHolder) currentStep).getHasContainers());
+                currentStep.getLabels().forEach(tinkerGraphStep::addLabel);
+                traversal.removeStep(currentStep);
                 currentStep = currentStep.getNextStep();
             }
         }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/73cf5284/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphStepStrategyTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphStepStrategyTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphStepStrategyTest.java
new file mode 100644
index 0000000..0e2a188
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/optimization/TinkerGraphStepStrategyTest.java
@@ -0,0 +1,71 @@
+/*
+ *
+ *  * 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.tinkergraph.process.traversal.strategy.optimization;
+
+import org.apache.tinkerpop.gremlin.process.traversal.P;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep;
+import org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.step.sideEffect.TinkerGraphStep;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+
+public class TinkerGraphStepStrategyTest {
+
+    @Test
+    public void shouldFoldInHasContainers() {
+        TinkerGraph graph = TinkerGraph.open();
+        GraphTraversalSource g = graph.traversal();
+        ////
+        GraphTraversal.Admin traversal = g.V().has("name", "marko").asAdmin();
+        assertEquals(2, traversal.getSteps().size());
+        assertEquals(HasStep.class, traversal.getEndStep().getClass());
+        traversal.applyStrategies();
+        assertEquals(1, traversal.getSteps().size());
+        assertEquals(TinkerGraphStep.class, traversal.getStartStep().getClass());
+        assertEquals(1, ((TinkerGraphStep) traversal.getStartStep()).getHasContainers().size());
+        assertEquals("name", ((TinkerGraphStep<?>) traversal.getStartStep()).getHasContainers().get(0).getKey());
+        assertEquals("marko", ((TinkerGraphStep<?>) traversal.getStartStep()).getHasContainers().get(0).getValue());
+        ////
+        traversal = g.V().has("name", "marko").has("age", P.gt(20)).asAdmin();
+        traversal.applyStrategies();
+        assertEquals(1, traversal.getSteps().size());
+        assertEquals(TinkerGraphStep.class, traversal.getStartStep().getClass());
+        assertEquals(2, ((TinkerGraphStep) traversal.getStartStep()).getHasContainers().size());
+        ////
+        traversal = g.V().has("name", "marko").out().has("name", "daniel").asAdmin();
+        traversal.applyStrategies();
+        assertEquals(3, traversal.getSteps().size());
+        assertEquals(TinkerGraphStep.class, traversal.getStartStep().getClass());
+        assertEquals(1, ((TinkerGraphStep) traversal.getStartStep()).getHasContainers().size());
+        assertEquals("name", ((TinkerGraphStep<?>) traversal.getStartStep()).getHasContainers().get(0).getKey());
+        assertEquals("marko", ((TinkerGraphStep<?>) traversal.getStartStep()).getHasContainers().get(0).getValue());
+        assertEquals(HasStep.class, traversal.getEndStep().getClass());
+    }
+
+}