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 2019/12/16 16:55:56 UTC

[tinkerpop] branch TINKERPOP-2315 created (now e396048)

This is an automated email from the ASF dual-hosted git repository.

spmallette pushed a change to branch TINKERPOP-2315
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git.


      at e396048  TINKERPOP-2315 Implement clone() for all GLVs

This branch includes the following new commits:

     new e396048  TINKERPOP-2315 Implement clone() for all GLVs

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[tinkerpop] 01/01: TINKERPOP-2315 Implement clone() for all GLVs

Posted by sp...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e3960486459152c31565642f772a8df0c57ca9f6
Author: stephen <sp...@gmail.com>
AuthorDate: Mon Dec 16 11:55:05 2019 -0500

    TINKERPOP-2315 Implement clone() for all GLVs
---
 CHANGELOG.asciidoc                                 |  1 +
 docs/src/upgrade/release-3.3.x.asciidoc            | 30 ++++++++++++++++++++++
 gremlin-dotnet/glv/GraphTraversal.template         |  8 ++++++
 .../Process/Traversal/GraphTraversal.cs            |  8 ++++++
 .../DriverRemoteConnection/GraphTraversalTests.cs  | 13 ++++++++++
 .../glv/GraphTraversalSource.template              |  8 ++++++
 .../lib/process/graph-traversal.js                 |  8 ++++++
 .../test/integration/traversal-test.js             | 14 ++++++++++
 gremlin-python/glv/GraphTraversalSource.template   |  3 +++
 .../gremlin_python/process/graph_traversal.py      |  3 +++
 .../tests/driver/test_driver_remote_connection.py  |  8 ++++++
 11 files changed, 104 insertions(+)

diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 83cab12..3209db9 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 
 * Improved error messaging for a `Cluster` with a bad `Channelizer` configuration in the Java driver.
 * Made `Cluster` be able to open configuration file on resources directory.
+* Implemented `Traversal.clone()` operations for all language variants.
 * Bump to Tornado 5.x for gremlin-python.
 * Deprecated `TraversalStrategies.applyStrategies()`.
 * Deprecated Jython support in `gremlin-python`.
diff --git a/docs/src/upgrade/release-3.3.x.asciidoc b/docs/src/upgrade/release-3.3.x.asciidoc
index 466cdd9..2e5ed8f 100644
--- a/docs/src/upgrade/release-3.3.x.asciidoc
+++ b/docs/src/upgrade/release-3.3.x.asciidoc
@@ -29,6 +29,36 @@ Please see the link:https://github.com/apache/tinkerpop/blob/3.3.10/CHANGELOG.as
 
 === Upgrading for Users
 
+==== Traversal Clone
+
+Once a traversal has been executed (i.e. iterated) it's internal state is such that it cannot be re-used:
+
+[source,text]
+----
+gremlin> t = g.V().count()
+==>6
+gremlin> t
+gremlin>
+----
+
+To re-use a traversal it must be copied with `clone()` as follows:
+
+[source,text]
+----
+gremlin> t = g.V().count()
+==>6
+gremlin> t.clone()
+==>6
+gremlin> t.clone()
+==>6
+----
+
+The ability to `clone()` has been exclusive to Java and was a missing component of other supported languages like
+Python, Javascript and .NET. This feature has now been added for all the language variants making the ability to
+re-use traversals consistent in all ecosystems.
+
+See: link:https://issues.apache.org/jira/browse/TINKERPOP-2315[TINKERPOP-2315]
+
 ==== Deprecated Jython Support
 
 Jython support in `gremlin-python` has been deprecated to focus on native Python 3.x support for 3.5.0 where Jython
diff --git a/gremlin-dotnet/glv/GraphTraversal.template b/gremlin-dotnet/glv/GraphTraversal.template
index 9e4b284..a8d4466 100644
--- a/gremlin-dotnet/glv/GraphTraversal.template
+++ b/gremlin-dotnet/glv/GraphTraversal.template
@@ -80,5 +80,13 @@ namespace Gremlin.Net.Process.Traversal
             return Wrap<$method.t1, $method.t2>(this);
         }
 <% } %>
+
+        /// <summary>
+        /// Make a copy of a traversal that is reset for iteration.
+        /// </summary>
+        public GraphTraversal<S, E> Clone()
+        {
+            return new GraphTraversal<S, E>(this.TraversalStrategies, this.Bytecode);
+        }
     }
 }
\ No newline at end of file
diff --git a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
index ef92edd..910c6e8 100644
--- a/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
+++ b/gremlin-dotnet/src/Gremlin.Net/Process/Traversal/GraphTraversal.cs
@@ -1677,5 +1677,13 @@ namespace Gremlin.Net.Process.Traversal
             return Wrap<S, E>(this);
         }
 
+
+        /// <summary>
+        /// Make a copy of a traversal that is reset for iteration.
+        /// </summary>
+        public GraphTraversal<S, E> Clone()
+        {
+            return new GraphTraversal<S, E>(this.TraversalStrategies, this.Bytecode);
+        }
     }
 }
\ No newline at end of file
diff --git a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs
index 9508eb7..c090fed 100644
--- a/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs
+++ b/gremlin-dotnet/test/Gremlin.Net.IntegrationTest/Process/Traversal/DriverRemoteConnection/GraphTraversalTests.cs
@@ -46,6 +46,19 @@ namespace Gremlin.Net.IntegrationTest.Process.Traversal.DriverRemoteConnection
         }
 
         [Fact]
+        public void g_V_Count_Clone()
+        {
+            var connection = _connectionFactory.CreateRemoteConnection();
+            var g = AnonymousTraversalSource.Traversal().WithRemote(connection);
+
+            var t = g.V().Count();
+
+            Assert.Equal(6, t.Next());
+            Assert.Equal(6, t.Clone().Next());
+            Assert.Equal(6, t.Clone().Next());
+        }
+
+        [Fact]
         public void g_VX1X_Next()
         {
             var connection = _connectionFactory.CreateRemoteConnection();
diff --git a/gremlin-javascript/glv/GraphTraversalSource.template b/gremlin-javascript/glv/GraphTraversalSource.template
index a684693..80476f1 100644
--- a/gremlin-javascript/glv/GraphTraversalSource.template
+++ b/gremlin-javascript/glv/GraphTraversalSource.template
@@ -113,6 +113,14 @@ class GraphTraversal extends Traversal {
   constructor(graph, traversalStrategies, bytecode) {
     super(graph, traversalStrategies, bytecode);
   }
+
+  /**
+   * Copy a traversal so as to reset and re-use it.
+   */
+  clone() {
+    return new GraphTraversal(this.graph, this.traversalStrategies, this.getBytecode());
+  }
+
   <% graphStepMethods.each{ method -> %>
   /**
    * Graph traversal <%= method %> method.
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js
index 6e61bdf..1b76667 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/lib/process/graph-traversal.js
@@ -201,6 +201,14 @@ class GraphTraversal extends Traversal {
   constructor(graph, traversalStrategies, bytecode) {
     super(graph, traversalStrategies, bytecode);
   }
+
+  /**
+   * Copy a traversal so as to reset and re-use it.
+   */
+  clone() {
+    return new GraphTraversal(this.graph, this.traversalStrategies, this.getBytecode());
+  }
+
   
   /**
    * Graph traversal V method.
diff --git a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js
index e68b615..453423a 100644
--- a/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js
+++ b/gremlin-javascript/src/main/javascript/gremlin-javascript/test/integration/traversal-test.js
@@ -79,6 +79,20 @@ describe('Traversal', function () {
       });
     });
   });
+  describe('#clone()', function () {
+    it('should reset a traversal when cloned', function () {
+      var g = traversal().withRemote(connection);
+      var t = g.V().count();
+      return t.next().then(function (item1) {
+            assert.ok(item1);
+            assert.strictEqual(item1.value, 6);
+            t.clone().next().then(function (item2) {
+              assert.ok(item2);
+              assert.strictEqual(item2.value, 6);
+            });
+      });
+    });
+  });
   describe('#next()', function () {
     it('should submit the traversal and return an iterator', function () {
       var g = traversal().withRemote(connection);
diff --git a/gremlin-python/glv/GraphTraversalSource.template b/gremlin-python/glv/GraphTraversalSource.template
index 9cd609e..fbb64a6 100644
--- a/gremlin-python/glv/GraphTraversalSource.template
+++ b/gremlin-python/glv/GraphTraversalSource.template
@@ -85,6 +85,9 @@ class GraphTraversal(Traversal):
 
     def __getattr__(self, key):
         return self.values(key)
+
+    def clone(self):
+        return GraphTraversal(self.graph, self.traversal_strategies, self.bytecode)
 <% graphStepMethods.each { method -> %>
     def <%= method %>(self, *args):
         self.bytecode.add_step("<%= toJava.call(method) %>", *args)
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
index d8ca628..c348d16 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
@@ -131,6 +131,9 @@ class GraphTraversal(Traversal):
     def __getattr__(self, key):
         return self.values(key)
 
+    def clone(self):
+        return GraphTraversal(self.graph, self.traversal_strategies, self.bytecode)
+
     def V(self, *args):
         self.bytecode.add_step("V", *args)
         return self
diff --git a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
index 1d5c0f5..30828d8 100644
--- a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
@@ -295,3 +295,11 @@ class TestDriverRemoteConnection(object):
         assert results
         results = t.side_effects.close()
         assert not results
+
+    def test_clone(self, remote_connection):
+        g = traversal().withRemote(remote_connection)
+        t = g.V().count()
+        assert 6 == t.next()
+        assert 6 == t.clone().next()
+        assert 6 == t.clone().next()
+