tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkupp...@apache.org
Subject [tinkerpop] 01/01: TINKERPOP-2112 Fixed folding in property() step
Date Wed, 02 Jan 2019 17:39:02 GMT
This is an automated email from the ASF dual-hosted git repository.

dkuppitz pushed a commit to branch TINKERPOP-2112
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git

commit afa65aff51cbd13d8ba66a30f01bb0da8b750406
Author: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
AuthorDate: Wed Jan 2 10:37:58 2019 -0700

    TINKERPOP-2112 Fixed folding in property() step
---
 .../traversal/dsl/graph/GraphTraversal.java        |  7 +-
 gremlin-test/features/map/AddVertex.feature        | 35 +++++++++
 .../process/traversal/step/map/AddVertexTest.java  | 71 ++++++++++++++++-
 .../tinkergraph/structure/TinkerGraphPlayTest.java | 91 ++--------------------
 4 files changed, 115 insertions(+), 89 deletions(-)

diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 92593c3..55051b3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -2081,9 +2081,12 @@ public interface GraphTraversal<S, E> extends Traversal<S,
E> {
 
         // if it can be detected that this call to property() is related to an addV/E() then
we can attempt to fold
         // the properties into that step to gain an optimization for those graphs that support
such capabilities.
-        final Step endStep = this.asAdmin().getEndStep();
+        Step endStep = this.asAdmin().getEndStep();
+        while (endStep instanceof AddPropertyStep) {
+            endStep = endStep.getPreviousStep();
+        }
         if ((endStep instanceof AddVertexStep || endStep instanceof AddEdgeStep || endStep
instanceof AddVertexStartStep || endStep instanceof AddEdgeStartStep) &&
-                keyValues.length == 0 && null == cardinality) {
+                keyValues.length == 0 && (null == cardinality || (VertexProperty.Cardinality.single.equals(cardinality)
&& key instanceof T))) {
             ((Mutating) endStep).addPropertyMutations(key, value);
         } else {
             this.asAdmin().addStep(new AddPropertyStep(this.asAdmin(), cardinality, key,
value));
diff --git a/gremlin-test/features/map/AddVertex.feature b/gremlin-test/features/map/AddVertex.feature
index 761916e..c541830 100644
--- a/gremlin-test/features/map/AddVertex.feature
+++ b/gremlin-test/features/map/AddVertex.feature
@@ -387,3 +387,38 @@ Feature: Step - addV()
       | result |
       | name |
 
+  Scenario: g_addV_propertyXsingle_id_1X_valueMapXtrueX
+    Given the empty graph
+    And using the parameter vid defined as "d[1].l"
+    And the traversal of
+      """
+      g.addV().property(Cardinality.single, T.id, vid).id()
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | "d[1].l" |
+
+  Scenario: g_addV_propertyXid_1X_propertyXsingle_k_vX_valueMapXtrueX
+    Given the empty graph
+    And using the parameter vid defined as "d[1].l"
+    And the traversal of
+      """
+      g.addV().property(T.id, vid).property(Cardinality.single, "k", "v").valueMap(true)
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | m[{"t[id]": "d[1].l", "t[label]": "vertex", "k": ["v"]}] |
+
+  Scenario: g_addV_propertyXsingle_k_vX_propertyXid_1X_valueMapXtrueX
+    Given the empty graph
+    And using the parameter vid defined as "d[1].l"
+    And the traversal of
+      """
+      g.addV().property(Cardinality.single, "k", "v").property(T.id, vid).valueMap(true)
+      """
+    When iterated to list
+    Then the result should be unordered
+      | result |
+      | m[{"t[id]": "d[1].l", "t[label]": "vertex", "k": ["v"]}] |
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexTest.java
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexTest.java
index f732a44..1db4c98 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/AddVertexTest.java
@@ -75,6 +75,12 @@ public abstract class AddVertexTest extends AbstractGremlinTest {
 
     public abstract Traversal<Vertex, Map<Object, Object>> get_g_V_asXaX_hasXname_markoX_outXcreatedX_asXbX_addVXselectXaX_labelX_propertyXtest_selectXbX_labelX_valueMapXtrueX();
 
+    public abstract Traversal<Vertex, Map<Object, Object>> get_g_addV_propertyXsingle_id_1X_valueMapXtrueX();
+
+    public abstract Traversal<Vertex, Map<Object, Object>> get_g_addV_propertyXid_1X_propertyXsingle_k_vX_valueMapXtrueX();
+
+    public abstract Traversal<Vertex, Map<Object, Object>> get_g_addV_propertyXsingle_k_vX_propertyXid_1X_valueMapXtrueX();
+
     @Test
     @LoadGraphWith(MODERN)
     @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
@@ -189,9 +195,8 @@ public abstract class AddVertexTest extends AbstractGremlinTest {
         assertFalse(traversal.hasNext());
         assertEquals("animal", mateo.label());
         assertEquals(3, IteratorUtils.count(mateo.properties("name")));
-        mateo.values("name").forEachRemaining(name -> {
-            assertTrue(name.equals("mateo") || name.equals("cateo") || name.equals("gateo"));
-        });
+        mateo.values("name").forEachRemaining(name ->
+                assertTrue(name.equals("mateo") || name.equals("cateo") || name.equals("gateo")));
         assertEquals(5, ((Integer) mateo.value("age")).intValue());
     }
 
@@ -207,7 +212,7 @@ public abstract class AddVertexTest extends AbstractGremlinTest {
             final Vertex vertex = traversal.next();
             assertEquals("animal", vertex.label());
             assertEquals(2, IteratorUtils.count(vertex.properties("name")));
-            List<String> names = IteratorUtils.asList(vertex.values("name"));
+            List names = IteratorUtils.asList(vertex.values("name"));
             assertEquals(2, names.size());
             assertTrue(names.contains("an animal"));
             assertTrue(names.contains("marko") || names.contains("vadas") || names.contains("josh")
|| names.contains("lop") || names.contains("ripple") || names.contains("peter"));
@@ -296,6 +301,49 @@ public abstract class AddVertexTest extends AbstractGremlinTest {
         assertEquals(3, map.size());
     }
 
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
+    public void g_addV_propertyXsingle_id_1X_valueMapXtrueX() {
+        final Traversal<Vertex, Map<Object,Object>> traversal = get_g_addV_propertyXsingle_id_1X_valueMapXtrueX();
+        printTraversalForm(traversal);
+        final Map<Object,Object> map = traversal.next();
+        assertFalse(traversal.hasNext());
+        assertEquals(1, map.get(T.id));
+        assertTrue(map.containsKey(T.label));
+        assertEquals(2, map.size());
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
+    public void g_addV_propertyXid_1X_propertyXsingle_k_vX_valueMapXtrueX() {
+        final Traversal<Vertex, Map<Object,Object>> traversal = get_g_addV_propertyXid_1X_propertyXsingle_k_vX_valueMapXtrueX();
+        printTraversalForm(traversal);
+        final Map<Object,Object> map = traversal.next();
+        assertFalse(traversal.hasNext());
+        assertEquals(1, map.get(T.id));
+        assertEquals("v", ((List) map.get("k")).get(0));
+        assertTrue(map.containsKey(T.label));
+        assertEquals(3, map.size());
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_CUSTOM_IDS)
+    public void g_addV_propertyXsingle_k_vX_propertyXid_1X_valueMapXtrueX() {
+        final Traversal<Vertex, Map<Object,Object>> traversal = get_g_addV_propertyXsingle_k_vX_propertyXid_1X_valueMapXtrueX();
+        printTraversalForm(traversal);
+        final Map<Object,Object> map = traversal.next();
+        assertFalse(traversal.hasNext());
+        assertEquals(1, map.get(T.id));
+        assertEquals("v", ((List) map.get("k")).get(0));
+        assertTrue(map.containsKey(T.label));
+        assertEquals(3, map.size());
+    }
+
     public static class Traversals extends AddVertexTest {
 
         @Override
@@ -362,5 +410,20 @@ public abstract class AddVertexTest extends AbstractGremlinTest {
         public Traversal<Vertex, Map<Object, Object>> get_g_V_asXaX_hasXname_markoX_outXcreatedX_asXbX_addVXselectXaX_labelX_propertyXtest_selectXbX_labelX_valueMapXtrueX()
{
             return g.V().as("a").has("name", "marko").out("created").as("b").addV(select("a").label()).property("test",
select("b").label()).valueMap(true);
         }
+
+        @Override
+        public Traversal<Vertex, Map<Object, Object>> get_g_addV_propertyXsingle_id_1X_valueMapXtrueX()
{
+            return g.addV().property(VertexProperty.Cardinality.single, T.id, 1).valueMap(true);
+        }
+
+        @Override
+        public Traversal<Vertex, Map<Object, Object>> get_g_addV_propertyXid_1X_propertyXsingle_k_vX_valueMapXtrueX()
{
+            return g.addV().property(T.id, 1).property(VertexProperty.Cardinality.single,
"k", "v").valueMap(true);
+        }
+
+        @Override
+        public Traversal<Vertex, Map<Object, Object>> get_g_addV_propertyXsingle_k_vX_propertyXid_1X_valueMapXtrueX()
{
+            return g.addV().property(VertexProperty.Cardinality.single, "k", "v").property(T.id,
1).valueMap(true);
+        }
     }
 }
\ No newline at end of file
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 e0018fc..e876e23 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
@@ -122,91 +122,16 @@ public class TinkerGraphPlayTest {
     @Ignore
     public void testPlayDK() throws Exception {
 
-        final Map<String, String> aliases = new HashMap<>();
-        aliases.put("marko","okram");
-        final GraphTraversalSource g = TinkerFactory.createModern().traversal();
-        /*g.withSideEffect("a", aliases).V().hasLabel("person").
-                values("name").as("n").
-                optional(select("a").select(select("n"))).
-                forEachRemaining(System.out::println);*/
+        final GraphTraversalSource g = TinkerGraph.open().traversal();
 
-        // shortest path lengths (by summed weight)
-        g.withSack(0.0).V().has("person", "name", "marko").
-                repeat(__.bothE().
-                        sack(sum).
-                            by("weight").
-                        otherV().
-                        group("m").
-                            by().
-                            by(sack().min()).as("x").
-                        // where(P.eq("m")).by(sack()).by(select(select("x"))). // could
be that easy, but "x" is unknown here
-                        filter(project("s","x").
-                                    by(sack()).
-                                    by(select("m").select(select("x"))).
-                                where("s", P.eq("x"))).
-                        group("p").
-                            by().
-                            by(project("path","length").
-                                    by(path().by("name").by("weight")).
-                                    by(sack()))
-                        ).
-                cap("p").unfold().
-                group().
-                    by(select(Column.keys).values("name")).
-                    by(Column.values).next().entrySet().
-                forEach(System.out::println);
+        g.addV().property(VertexProperty.Cardinality.single, T.id , "1").iterate();
+        g.addV().property(VertexProperty.Cardinality.single, "id", "1").iterate();
+        g.addV().property("id", "1").iterate();
 
-        System.out.println("---");
-
-        // longest path lengths (by summed weight)
-        g.withSack(0.0).V().has("person", "name", "marko").
-                repeat(__.bothE().simplePath().
-                        sack(sum).
-                          by("weight").
-                        otherV().
-                        group("m").
-                            by().
-                            by(sack().max()).as("x").
-                        filter(project("s","x").
-                                by(sack()).
-                                by(select("m").select(select("x"))).
-                                where("s", P.eq("x"))).
-                        group("p").
-                                by().
-                                by(project("path","length").
-                                        by(path().by("name").by("weight")).
-                                        by(sack()))
-                        ).
-                cap("p").unfold().
-                group().
-                    by(select(Column.keys).values("name")).
-                    by(Column.values).next().entrySet().
-                forEach(System.out::println);
-
-        System.out.println("---");
-
-        // all shortest paths (by summed weight)
-        g.withSack(0.0).V().as("a").
-                repeat(__.bothE().
-                        sack(sum).
-                            by("weight").
-                        otherV().as("b").
-                        group("m").
-                            by(select("a","b").by("name")).
-                            by(sack().min()).
-                        filter(project("s","x").
-                                by(sack()).
-                                by(select("m").select(select("a", "b").by("name"))).
-                               where("s", P.eq("x"))).
-                        group("p").
-                            by(select("a","b").by("name")).
-                            by(map(union(path().by("name").by("weight"), sack()).fold()))
-                ).
-                cap("p").unfold().
-                order().
-                    by(select(Column.keys).select("a")).
-                    by(select(Column.keys).select("b")).
-                forEachRemaining(System.out::println);
+        g.addV().property(T.id , "id1").property(VertexProperty.Cardinality.single, "k",
"v")
+                .forEachRemaining(System.out::println);
+        g.addV().property(VertexProperty.Cardinality.single, "k", "v").property(T.id , "id2")
+                .forEachRemaining(System.out::println);
     }
 
     @Test


Mime
View raw message