tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject [35/50] incubator-tinkerpop git commit: Fixed. There is now TraversalHelper.isNotBeyondElementId(). This ensures that any CollectingBarrierStep or other end-step for TraverserMapReduce throws a ComputerVerificationStrategyException is the by() modulation
Date Thu, 29 Oct 2015 23:29:56 GMT
Fixed. There is now TraversalHelper.isNotBeyondElementId(). This ensures that any CollectingBarrierStep
or other end-step for TraverserMapReduce throws a ComputerVerificationStrategyException is
the by() modulation tries to touch anything more than the Element id (though if its a string,
list, etc. that is okay). I added @dkuppitz two examples that should work and now they do
work. Furthermore, all existing traversal tests pass.


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

Branch: refs/heads/TINKERPOP3-925
Commit: d9cf614fcb1355a33bdf1ec007aa569f561f32b3
Parents: 45bf33d
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Wed Oct 28 15:30:31 2015 -0600
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Wed Oct 28 15:30:31 2015 -0600

----------------------------------------------------------------------
 .../step/util/TraversalComparator.java          |  5 +-
 .../ComputerVerificationStrategy.java           | 11 +---
 .../process/traversal/util/TraversalHelper.java | 20 +++++++
 .../traversal/step/map/GroovyOrderTest.groovy   | 10 ++++
 .../process/traversal/step/map/OrderTest.java   | 58 +++++++++++++++++++-
 5 files changed, 91 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d9cf614f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/TraversalComparator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/TraversalComparator.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/TraversalComparator.java
index 374a61b..fe65d58 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/TraversalComparator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/TraversalComparator.java
@@ -19,6 +19,7 @@
 package org.apache.tinkerpop.gremlin.process.traversal.step.util;
 
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
 
 import java.io.Serializable;
@@ -44,7 +45,9 @@ public final class TraversalComparator<S, E> implements Comparator<S>,
Serializa
 
     @Override
     public int compare(final S start1, final S start2) {
-        return this.comparator.compare(TraversalUtil.apply(start1, this.traversal), TraversalUtil.apply(start2,
this.traversal));
+        return start1 instanceof Traverser ?
+                this.comparator.compare(TraversalUtil.apply((Traverser.Admin<S>) start1,
this.traversal), TraversalUtil.apply((Traverser.Admin<S>) start2, this.traversal)) :
+                this.comparator.compare(TraversalUtil.apply(start1, this.traversal), TraversalUtil.apply(start2,
this.traversal));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d9cf614f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/ComputerVerificationStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/ComputerVerificationStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/ComputerVerificationStrategy.java
index 259531a..4561272 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/ComputerVerificationStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/ComputerVerificationStrategy.java
@@ -22,9 +22,6 @@ import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.Computer
 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.lambda.ConstantTraversal;
-import org.apache.tinkerpop.gremlin.process.traversal.lambda.IdentityTraversal;
-import org.apache.tinkerpop.gremlin.process.traversal.lambda.TokenTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Bypassing;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Mutating;
 import org.apache.tinkerpop.gremlin.process.traversal.step.PathProcessor;
@@ -46,9 +43,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierS
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.SupplyingBarrierStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.T;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
 
 import java.util.Arrays;
 import java.util.HashSet;
@@ -83,10 +77,7 @@ public final class ComputerVerificationStrategy extends AbstractTraversalStrateg
                 throw new VerificationException("GraphComputer does not support traversals
starting from a non-GraphStep: " + traversal.getStartStep(), traversal);
             ///
             if (endStep instanceof CollectingBarrierStep && endStep instanceof TraversalParent)
{
-                if (((TraversalParent) endStep).getLocalChildren().stream().filter(t ->
-                        !(t instanceof IdentityTraversal) &&
-                                !(t instanceof ConstantTraversal) &&  // for SampleStep
-                                !(t instanceof TokenTraversal && ((TokenTraversal)
t).getToken().equals(T.id))).findAny().isPresent())
+                if (((TraversalParent) endStep).getLocalChildren().stream().filter(t ->
!TraversalHelper.isNotBeyondElementId(t)).findAny().isPresent())
                     throw new VerificationException("A final CollectingBarrierStep can not
process an element beyond its id: " + endStep, traversal);
             }
             ///

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d9cf614f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
index f4f96c7..af98fa6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
@@ -20,6 +20,8 @@ package org.apache.tinkerpop.gremlin.process.traversal.util;
 
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.lambda.ElementValueTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.lambda.TokenTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder;
 import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
 import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
@@ -31,6 +33,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.filter.WhereTraversal
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertyMapStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.StartStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
@@ -57,6 +60,23 @@ public final class TraversalHelper {
     private TraversalHelper() {
     }
 
+    public static boolean isNotBeyondElementId(final Traversal.Admin<?, ?> traversal)
{
+        if (traversal instanceof TokenTraversal && !((TokenTraversal) traversal).getToken().equals(T.id))
+            return false;
+        else if (traversal instanceof ElementValueTraversal)
+            return false;
+        else
+            return !traversal.getSteps().stream()
+                    .filter(step -> step instanceof VertexStep ||
+                            step instanceof EdgeVertexStep ||
+                            step instanceof PropertiesStep ||
+                            step instanceof PropertyMapStep ||
+                            (step instanceof TraversalParent &&
+                                    (((TraversalParent) step).getLocalChildren().stream().filter(t
-> !TraversalHelper.isNotBeyondElementId(t)).findAny().isPresent() ||
+                                            ((TraversalParent) step).getGlobalChildren().stream().filter(t
-> !TraversalHelper.isNotBeyondElementId(t)).findAny().isPresent())))
+                    .findAny().isPresent();
+    }
+
     public static boolean isLocalStarGraph(final Traversal.Admin<?, ?> traversal) {
         return isLocalStarGraph(traversal, 'v');
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d9cf614f/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyOrderTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyOrderTest.groovy
b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyOrderTest.groovy
index b2393d5..4b1168f 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyOrderTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/process/traversal/step/map/GroovyOrderTest.groovy
@@ -86,5 +86,15 @@ public abstract class GroovyOrderTest {
         public Traversal<Vertex, Map<String, List<Vertex>>> get_g_V_group_byXlabelX_byXnameX_byXorderXlocalX_byXdecrXX()
{
             TraversalScriptHelper.compute("g.V.group.by(label).by(values('name').order().by(decr).fold())",
g)
         }
+
+        @Override
+        public Traversal<Vertex, List<Double>> get_g_V_localXbothE_weight_foldX_order_byXsumXlocalX_decrX()
{
+            TraversalScriptHelper.compute("g.V.local(__.bothE.weight.fold).order.by(sum(local),
decr)", g)
+        }
+
+        @Override
+        public Traversal<Vertex, Map<String, Object>> get_g_V_asXvX_mapXbothE_weight_foldX_sumXlocalX_asXsX_selectXv_sX_order_byXselectXsX_decrX()
{
+            TraversalScriptHelper.compute("g.V.as('v').map(__.bothE.weight.fold).sum(local).as('s').select('v',
's').order.by(select('s'),decr)", g);
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d9cf614f/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
index 99dae26..cb0674d 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/OrderTest.java
@@ -70,6 +70,10 @@ public abstract class OrderTest extends AbstractGremlinProcessTest {
 
     public abstract Traversal<Vertex, Map<String, List<Vertex>>> get_g_V_group_byXlabelX_byXnameX_byXorderXlocalX_byXdecrXX();
 
+    public abstract Traversal<Vertex, List<Double>> get_g_V_localXbothE_weight_foldX_order_byXsumXlocalX_decrX();
+
+    public abstract Traversal<Vertex, Map<String, Object>> get_g_V_asXvX_mapXbothE_weight_foldX_sumXlocalX_asXsX_selectXv_sX_order_byXselectXsX_decrX();
+
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_name_order() {
@@ -97,7 +101,7 @@ public abstract class OrderTest extends AbstractGremlinProcessTest {
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_order_byXname_incrX_name() {
-        final Traversal<Vertex,String> traversal = get_g_V_order_byXname_incrX_name();
+        final Traversal<Vertex, String> traversal = get_g_V_order_byXname_incrX_name();
         printTraversalForm(traversal);
         assertCommon(traversal);
     }
@@ -105,7 +109,7 @@ public abstract class OrderTest extends AbstractGremlinProcessTest {
     @Test
     @LoadGraphWith(MODERN)
     public void g_V_order_byXnameX_name() {
-        final Traversal<Vertex,String> traversal = get_g_V_order_byXnameX_name();
+        final Traversal<Vertex, String> traversal = get_g_V_order_byXnameX_name();
         printTraversalForm(traversal);
         assertCommon(traversal);
     }
@@ -246,6 +250,47 @@ public abstract class OrderTest extends AbstractGremlinProcessTest {
         assertEquals("vadas", list.get(0));
     }
 
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_localXbothE_weight_foldX_order_byXsumXlocalX_decrX() {
+        final Traversal<Vertex, List<Double>> traversal = get_g_V_localXbothE_weight_foldX_order_byXsumXlocalX_decrX();
+        final List<List<Double>> list = traversal.toList();
+        assertEquals(list.get(0).size(), 3);
+        assertEquals(list.get(1).size(), 3);
+        //assertEquals(list.get(2).size(),3);  // they both have value 1.0 and thus can't
guarantee a tie order
+        //assertEquals(list.get(3).size(),1);
+        assertEquals(list.get(4).size(), 1);
+        assertEquals(list.get(5).size(), 1);
+        ///
+        assertEquals(2.4d, list.get(0).stream().reduce(0.0d, (a, b) -> a + b), 0.01d);
+        assertEquals(1.9d, list.get(1).stream().reduce(0.0d, (a, b) -> a + b), 0.01d);
+        assertEquals(1.0d, list.get(2).stream().reduce(0.0d, (a, b) -> a + b), 0.01d);
+        assertEquals(1.0d, list.get(3).stream().reduce(0.0d, (a, b) -> a + b), 0.01d);
+        assertEquals(0.5d, list.get(4).stream().reduce(0.0d, (a, b) -> a + b), 0.01d);
+        assertEquals(0.2d, list.get(5).stream().reduce(0.0d, (a, b) -> a + b), 0.01d);
+    }
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void g_V_asXvX_mapXbothE_weight_foldX_sumXlocalX_asXsX_selectXv_sX_order_byXselectXsX_decrX()
{
+        final Traversal<Vertex, Map<String, Object>> traversal = get_g_V_asXvX_mapXbothE_weight_foldX_sumXlocalX_asXsX_selectXv_sX_order_byXselectXsX_decrX();
+        final List<Map<String, Object>> list = traversal.toList();
+        assertEquals(convertToVertex(graph, "josh"), list.get(0).get("v"));
+        assertEquals(2.4d, (Double) list.get(0).get("s"), 0.1d);
+        ///
+        assertEquals(convertToVertex(graph, "marko"), list.get(1).get("v"));
+        assertEquals(1.9d, (Double) list.get(1).get("s"), 0.1d);
+        //
+        assertEquals(1.0d, (Double) list.get(2).get("s"), 0.1d);   // they both have 1.0
so you can't test the "v" as().
+        assertEquals(1.0d, (Double) list.get(3).get("s"), 0.1d);
+        ///
+        assertEquals(convertToVertex(graph, "vadas"), list.get(4).get("v"));
+        assertEquals(0.5d, (Double) list.get(4).get("s"), 0.1d);
+        ///
+        assertEquals(convertToVertex(graph, "peter"), list.get(5).get("v"));
+        assertEquals(0.2d, (Double) list.get(5).get("s"), 0.1d);
+    }
+
     public static class Traversals extends OrderTest {
 
         @Override
@@ -307,5 +352,14 @@ public abstract class OrderTest extends AbstractGremlinProcessTest {
             return g.V().<String, List<Vertex>>group().by(T.label).by(__.values("name").order().by(Order.decr).fold());
         }
 
+        @Override
+        public Traversal<Vertex, List<Double>> get_g_V_localXbothE_weight_foldX_order_byXsumXlocalX_decrX()
{
+            return g.V().local(__.bothE().<Double>values("weight").fold()).order().by(__.sum(Scope.local),
Order.decr);
+        }
+
+        @Override
+        public Traversal<Vertex, Map<String, Object>> get_g_V_asXvX_mapXbothE_weight_foldX_sumXlocalX_asXsX_selectXv_sX_order_byXselectXsX_decrX()
{
+            return g.V().as("v").map(__.bothE().<Double>values("weight").fold()).sum(Scope.local).as("s").select("v",
"s").order().by(__.select("s"), Order.decr);
+        }
     }
 }


Mime
View raw message