tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [21/27] incubator-tinkerpop git commit: backpropagated VertexComputing step labels for a robust as().select().path()-experience when working with OLAP VertexProgramSteps. Added a test case to PageRankTest that verifies all is golden.
Date Fri, 19 Feb 2016 16:26:52 GMT
backpropagated VertexComputing step labels for a robust as().select().path()-experience when
working with OLAP VertexProgramSteps. Added a test case to PageRankTest that verifies all
is golden.


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

Branch: refs/heads/master
Commit: 88fe7c90bfb6f9d2c86c8c2447dce0f0a0a6ae45
Parents: 0c25524
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Wed Feb 17 16:46:48 2016 -0700
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Wed Feb 17 16:46:48 2016 -0700

----------------------------------------------------------------------
 .../decoration/VertexProgramStrategy.java       | 20 +++++++++++++++-
 .../step/map/GroovyPageRankTest.groovy          |  5 ++++
 .../traversal/step/map/PageRankTest.java        | 25 ++++++++++++++++++++
 .../structure/TinkerGraphPlayTest.java          |  8 +++----
 4 files changed, 53 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/88fe7c90/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
index 7e9833b..2921623 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/VertexProgramStrategy.java
@@ -38,7 +38,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.util.EmptyTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 
+import java.util.HashSet;
 import java.util.Optional;
+import java.util.Set;
 import java.util.function.Function;
 
 /**
@@ -70,8 +72,22 @@ public final class VertexProgramStrategy extends AbstractTraversalStrategy<Trave
             return;
         }
 
+        // back propagate as()-labels off of vertex computing steps
+        Step<?, ?> currentStep = traversal.getEndStep();
+        final Set<String> currentLabels = new HashSet<>();
+        while (!(currentStep instanceof EmptyStep)) {
+            if (currentStep instanceof VertexComputing) {
+                currentLabels.addAll(currentStep.getLabels());
+                currentStep.getLabels().forEach(currentStep::removeLabel);
+            } else {
+                currentLabels.forEach(currentStep::addLabel);
+                currentLabels.clear();
+            }
+            currentStep = currentStep.getPreviousStep();
+        }
+
         // push GraphStep forward in the chain to reduce the number of TraversalVertexProgram
compilations
-        Step<?, ?> currentStep = traversal.getStartStep();
+        currentStep = traversal.getStartStep();
         while (!(currentStep instanceof EmptyStep)) {
             if (currentStep instanceof GraphStep && currentStep.getNextStep() instanceof
VertexComputing) {
                 int index = TraversalHelper.stepIndex(currentStep.getNextStep(), traversal);
@@ -80,6 +96,8 @@ public final class VertexProgramStrategy extends AbstractTraversalStrategy<Trave
             }
             currentStep = currentStep.getNextStep();
         }
+
+
         // wrap all non-VertexComputing steps into a TraversalVertexProgramStep
         currentStep = traversal.getStartStep();
         while (!(currentStep instanceof EmptyStep)) {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/88fe7c90/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyPageRankTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyPageRankTest.groovy
b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyPageRankTest.groovy
index 963846f..22ffb0c 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyPageRankTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyPageRankTest.groovy
@@ -54,5 +54,10 @@ public abstract class GroovyPageRankTest {
         public Traversal<Vertex, Map<String, List<Object>>> get_g_V_hasLabelXpersonX_pageRank_byXpageRankX_order_byXpageRankX_valueMapXname_pageRankX()
{
             new ScriptTraversal<>(g, "gremlin-groovy", "g.V.hasLabel('person').pageRank.by('pageRank').order.by('pageRank').valueMap('name',
'pageRank')")
         }
+
+        @Override
+        public Traversal<Vertex, Map<String, Object>> get_g_V_pageRank_byXpageRankX_asXaX_outXknowsX_pageRank_asXbX_selectXa_bX()
{
+            new ScriptTraversal<>(g, "gremlin-groovy", "g.V.pageRank.by('pageRank').as('a').out('knows').values('pageRank').as('b').select('a',
'b')")
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/88fe7c90/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java
index b0cd252..d29230b 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/PageRankTest.java
@@ -54,6 +54,8 @@ public abstract class PageRankTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Map<String, List<Object>>> get_g_V_hasLabelXpersonX_pageRank_byXpageRankX_order_byXpageRankX_valueMapXname_pageRankX();
 
+    public abstract Traversal<Vertex, Map<String, Object>> get_g_V_pageRank_byXpageRankX_asXaX_outXknowsX_pageRank_asXbX_selectXa_bX();
+
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_pageRank() {
@@ -139,6 +141,24 @@ public abstract class PageRankTest extends AbstractGremlinProcessTest
{
         assertEquals(4, counter);
     }
 
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_pageRank_byXpageRankX_asXaX_outXknowsX_pageRank_asXbX_selectXa_bX() {
+        final Traversal<Vertex, Map<String, Object>> traversal = get_g_V_pageRank_byXpageRankX_asXaX_outXknowsX_pageRank_asXbX_selectXa_bX();
+        printTraversalForm(traversal);
+        int counter = 0;
+        while (traversal.hasNext()) {
+            final Map<String, Object> map = traversal.next();
+            assertEquals(2, map.size());
+            Vertex vertex = (Vertex) map.get("a");
+            double pageRank = (Double) map.get("b");
+            assertEquals(convertToVertexId("marko"), vertex.id());
+            assertTrue(pageRank > 0.15d);
+            counter++;
+        }
+        assertEquals(2, counter);
+    }
+
     public static class Traversals extends PageRankTest {
 
         @Override
@@ -165,5 +185,10 @@ public abstract class PageRankTest extends AbstractGremlinProcessTest
{
         public Traversal<Vertex, Map<String, List<Object>>> get_g_V_hasLabelXpersonX_pageRank_byXpageRankX_order_byXpageRankX_valueMapXname_pageRankX()
{
             return g.V().hasLabel("person").pageRank().by("pageRank").order().by("pageRank").valueMap("name",
"pageRank");
         }
+
+        @Override
+        public Traversal<Vertex, Map<String, Object>> get_g_V_pageRank_byXpageRankX_asXaX_outXknowsX_pageRank_asXbX_selectXa_bX()
{
+            return g.V().pageRank().by("pageRank").as("a").out("knows").values("pageRank").as("b").select("a",
"b");
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/88fe7c90/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index 7fdf724..94c7ecc 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -66,12 +66,12 @@ public class TinkerGraphPlayTest {
     @Ignore
     public void testPlay8() throws Exception {
         Graph graph = TinkerFactory.createModern();
-        GraphTraversalSource g = graph.traversal();//.withComputer(); //GraphTraversalSource.computer());
+        GraphTraversalSource g = graph.traversal().withComputer(); //GraphTraversalSource.computer());
         //System.out.println(g.V().outE("knows").identity().inV().count().is(P.eq(5)).explain());
         //System.out.println(g.V().hasLabel("person").fold().order(Scope.local).by("age").toList());
-        System.out.println(g.V().peerPressure().toString());
-        System.out.println(g.V().peerPressure().iterate().toString());
-        System.out.println(g.V().peerPressure().toList());
+        System.out.println(g.V().pageRank().by("pageRank").as("a").out("knows").values("pageRank").as("b").select("a",
"b").toString());
+        System.out.println(g.V().pageRank().by("pageRank").as("a").out("knows").values("pageRank").as("b").select("a",
"b").iterate().toString());
+        System.out.println(g.V().pageRank().by("pageRank").as("a").out("knows").values("pageRank").as("b").select("a",
"b").toList());
         //System.out.println(g.V().pageRank().order().by(PageRankVertexProgram.PAGE_RANK).valueMap().toList());
     }
 


Mime
View raw message