You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2016/02/11 13:32:12 UTC

[1/9] incubator-tinkerpop git commit: Added another `edge()` method in `ScriptElementFactory` that allows to set explicit edge ids.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/tp31 c07d69826 -> f1c696794


Added another `edge()` method in `ScriptElementFactory` that allows to set explicit edge ids.


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

Branch: refs/heads/tp31
Commit: 50d5dd9bdb52633d9655f5a476f9885e6ff298d7
Parents: b07400c
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Tue Feb 9 19:08:54 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Tue Feb 9 19:08:54 2016 +0100

----------------------------------------------------------------------
 docs/src/reference/implementations.asciidoc                      | 1 +
 .../gremlin/hadoop/structure/io/script/ScriptRecordReader.java   | 4 ++++
 2 files changed, 5 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/50d5dd9b/docs/src/reference/implementations.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/implementations.asciidoc b/docs/src/reference/implementations.asciidoc
index 439123d..6b29ae7 100644
--- a/docs/src/reference/implementations.asciidoc
+++ b/docs/src/reference/implementations.asciidoc
@@ -1551,6 +1551,7 @@ Vertex vertex(Object id); // get or create the vertex with the given id
 Vertex vertex(Object id, String label); // get or create the vertex with the given id and label
 Edge edge(Vertex out, Vertex in); // create an edge between the two given vertices
 Edge edge(Vertex out, Vertex in, String label); // create an edge between the two given vertices using the given label
+Edge edge(Vertex out, Vertex in, Object id, String label); // create an edge between the two given vertices using the given edge id and label
 
 An appropriate `parse()` for the above adjacency list file is:
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/50d5dd9b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
index 4cc1602..b5e1cc0 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
@@ -138,5 +138,9 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
         public Edge edge(final Vertex out, final Vertex in, final String label) {
             return out.addEdge(label, in);
         }
+
+        public Edge edge(final Vertex out, final Vertex in, final Object id, final String label) {
+            return out.addEdge(label, in, T.id, id);
+        }
     }
 }


[6/9] incubator-tinkerpop git commit: updated ScriptInputFormat section in reference docs

Posted by dk...@apache.org.
updated ScriptInputFormat section in reference docs


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

Branch: refs/heads/tp31
Commit: 19c419731e6b5bdafff072ed371b6e89e9e1779f
Parents: af62e3c
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed Feb 10 16:29:14 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Wed Feb 10 16:29:14 2016 +0100

----------------------------------------------------------------------
 docs/src/reference/implementations.asciidoc | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/19c41973/docs/src/reference/implementations.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/implementations.asciidoc b/docs/src/reference/implementations.asciidoc
index 5eadef3..5b7e3e4 100644
--- a/docs/src/reference/implementations.asciidoc
+++ b/docs/src/reference/implementations.asciidoc
@@ -1544,20 +1544,14 @@ mapper in the Hadoop job. The script must have the following method defined:
 [source,groovy]
 def parse(String line, ScriptElementFactory factory) { ... }
 
-`ScriptElementFactory` provides the following 4 methods:
-
-[source,java]
-Graph graph(); // get a reference to the local star graph
-Vertex vertex(Object id); // get or create the vertex with the given id
-Vertex vertex(Object id, String label); // get or create the vertex with the given id and label
-Edge edge(Vertex out, Vertex in); // create an edge between the two given vertices
-Edge edge(Vertex out, Vertex in, String label); // create an edge between the two given vertices using the given label
+`ScriptElementFactory` is a legacy from previous version and, although it's still functional, it should no longer be used.
+In order to create vertices and edges, the `parse()` method gets access to a global variable named `graph`, which holds
+the local `StarGraph` for the current line/vertex.
 
 An appropriate `parse()` for the above adjacency list file is:
 
 [source,groovy]
 def parse(line, factory) {
-    def graph = factory.graph()
     def parts = line.split(/ /)
     def (id, label, name, x) = parts[0].split(/:/).toList()
     def v1 = graph.addVertex(T.id, id, T.label, label)


[9/9] incubator-tinkerpop git commit: Merge branch 'TINKERPOP-1137' into tp31

Posted by dk...@apache.org.
Merge branch 'TINKERPOP-1137' into tp31


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

Branch: refs/heads/tp31
Commit: f1c696794227c752536ce630fafda8d4b7a7de02
Parents: c07d698 4f885f0
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu Feb 11 13:31:40 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Thu Feb 11 13:31:40 2016 +0100

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 data/script-input.groovy                        |  9 ++++---
 docs/src/reference/implementations.asciidoc     | 17 +++++--------
 .../io/script/script-input-grateful-dead.groovy |  2 +-
 .../structure/io/script/script-input.groovy     | 14 +++++------
 .../structure/io/script/ScriptRecordReader.java | 26 ++++++++++++++------
 6 files changed, 38 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f1c69679/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --cc CHANGELOG.asciidoc
index c131d5e,d07d44a..86e9229
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@@ -26,7 -26,7 +26,8 @@@ image::https://raw.githubusercontent.co
  TinkerPop 3.1.2 (NOT OFFICIALLY RELEASED YET)
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  
 +* `TraversalExplanation` is now `Serializable` and registered with `GryoMapper`.
+ * Deprecated `ScriptElementFactory` and made the local `StarGraph` globally available for `ScriptInputFormat`'s `parse()` method.
  * Optimized memory-usage in `TraversalVertexProgram`.
  * Greatly reduced the amount of objects required in OLAP for the `ReducingBarrierStep` steps.
  


[5/9] incubator-tinkerpop git commit: updated CHANGELOG

Posted by dk...@apache.org.
updated CHANGELOG


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

Branch: refs/heads/tp31
Commit: af62e3c20f5e375886b95c670977e87d0cc770fd
Parents: e71139c
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed Feb 10 15:50:30 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Wed Feb 10 15:50:30 2016 +0100

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/af62e3c2/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 0cd221f..d07d44a 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/
 TinkerPop 3.1.2 (NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Deprecated `ScriptElementFactory` and made the local `StarGraph` globally available for `ScriptInputFormat`'s `parse()` method.
 * Optimized memory-usage in `TraversalVertexProgram`.
 * Greatly reduced the amount of objects required in OLAP for the `ReducingBarrierStep` steps.
 


[4/9] incubator-tinkerpop git commit: Marked `ScriptElementFactory` as deprecated and made the local star graph globally available for the ScriptInputFormat's user defined parse() method.

Posted by dk...@apache.org.
Marked `ScriptElementFactory` as deprecated and made the local star graph globally available for the ScriptInputFormat's user defined parse() method.


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

Branch: refs/heads/tp31
Commit: e71139ceba2e1ba0fa214fd2691264067e8809d3
Parents: 99b5791
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed Feb 10 15:45:40 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Wed Feb 10 15:45:40 2016 +0100

----------------------------------------------------------------------
 data/script-input.groovy                        |  3 ++-
 .../io/script/script-input-grateful-dead.groovy |  1 -
 .../structure/io/script/script-input.groovy     |  1 -
 .../structure/io/script/ScriptRecordReader.java | 28 +++++++++++---------
 4 files changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e71139ce/data/script-input.groovy
----------------------------------------------------------------------
diff --git a/data/script-input.groovy b/data/script-input.groovy
index 3a2dfd8..4e1d219 100644
--- a/data/script-input.groovy
+++ b/data/script-input.groovy
@@ -17,7 +17,8 @@
  * under the License.
  */
 def parse(line, factory) {
-    def graph = factory.graph()
+    // "factory" should no longer be used, as ScriptElementFactory is now deprecated
+    // instead use the global "graph" variable which is the local star graph for the current element
     def parts = line.split(/ /)
     def (id, label, name, x) = parts[0].split(/:/).toList()
     def v1 = graph.addVertex(T.id, id, T.label, label)

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e71139ce/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
index 9dbc5fc..38ff99a 100644
--- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
@@ -18,7 +18,6 @@
  */
 
 def parse(line, factory) {
-    def graph = factory.graph()
     def (vertex, outEdges, inEdges) = line.split(/\t/, 3)
     def (v1id, v1label, v1props) = vertex.split(/,/, 3)
     def v1 = graph.addVertex(T.id, v1id.toInteger(), T.label, v1label)

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e71139ce/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy
index 096fdd4..991aef3 100644
--- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy
@@ -19,7 +19,6 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty
  * under the License.
  */
 def parse(line, factory) {
-    def graph = factory.graph()
     def parts = line.split(/\t/)
     def (id, label, name, x) = parts[0].split(/:/).toList()
     def v1 = graph.addVertex(T.id, id, T.label, label)

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e71139ce/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
index 4615b51..73a48e7 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
@@ -18,6 +18,7 @@
  */
 package org.apache.tinkerpop.gremlin.hadoop.structure.io.script;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
@@ -51,12 +52,15 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
 
     protected final static String SCRIPT_FILE = "gremlin.hadoop.scriptInputFormat.script";
     //protected final static String SCRIPT_ENGINE = "gremlin.hadoop.scriptInputFormat.scriptEngine";
+    private final static String GRAPH = "graph";
     private final static String LINE = "line";
     private final static String FACTORY = "factory";
     private final static String READ_CALL = "parse(" + LINE + "," + FACTORY + ")";
     private final VertexWritable vertexWritable = new VertexWritable();
     private final LineRecordReader lineRecordReader;
+
     private ScriptEngine engine;
+    private String parse;
 
     public ScriptRecordReader() {
         this.lineRecordReader = new LineRecordReader();
@@ -71,11 +75,7 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
         final FileSystem fs = FileSystem.get(configuration);
         try (final InputStream stream = fs.open(new Path(configuration.get(SCRIPT_FILE)));
              final InputStreamReader reader = new InputStreamReader(stream)) {
-            try {
-                this.engine.eval(reader);
-            } catch (ScriptException e) {
-                throw new IOException(e.getMessage(), e);
-            }
+            this.parse = String.join("\n", IOUtils.toString(reader), READ_CALL);
         }
     }
 
@@ -85,9 +85,12 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
             if (!this.lineRecordReader.nextKeyValue()) return false;
             try {
                 final Bindings bindings = this.engine.createBindings();
+                final StarGraph graph = StarGraph.open();
+                final ScriptElementFactory factory = new ScriptElementFactory(graph);
+                bindings.put(GRAPH, graph);
                 bindings.put(LINE, this.lineRecordReader.getCurrentValue().toString());
-                bindings.put(FACTORY, new ScriptElementFactory());
-                final Vertex vertex = (Vertex) engine.eval(READ_CALL, bindings);
+                bindings.put(FACTORY, factory);
+                final Vertex vertex = (Vertex) engine.eval(this.parse, bindings);
                 if (vertex != null) {
                     this.vertexWritable.set(vertex);
                     return true;
@@ -118,12 +121,17 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
         this.lineRecordReader.close();
     }
 
+    @Deprecated
     protected class ScriptElementFactory {
 
         private final StarGraph graph;
 
         public ScriptElementFactory() {
-            this.graph = StarGraph.open();
+            this(StarGraph.open());
+        }
+
+        public ScriptElementFactory(final StarGraph graph) {
+            this.graph = graph;
         }
 
         public Vertex vertex(final Object id) {
@@ -142,9 +150,5 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
         public Edge edge(final Vertex out, final Vertex in, final String label) {
             return out.addEdge(label, in);
         }
-
-        public StarGraph graph() {
-            return this.graph;
-        }
     }
 }


[8/9] incubator-tinkerpop git commit: reverted changes in ScriptInput parser in order to verify that backwards compatibility is preserved

Posted by dk...@apache.org.
reverted changes in ScriptInput parser in order to verify that backwards compatibility is preserved


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

Branch: refs/heads/tp31
Commit: 4f885f04b92b92ff0ee8a30a781bee837fac8287
Parents: 3cc0d8a
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed Feb 10 23:38:23 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Wed Feb 10 23:38:23 2016 +0100

----------------------------------------------------------------------
 .../structure/io/script/script-input-grateful-dead.groovy      | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/4f885f04/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
index 38ff99a..b334207 100644
--- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
@@ -20,7 +20,7 @@
 def parse(line, factory) {
     def (vertex, outEdges, inEdges) = line.split(/\t/, 3)
     def (v1id, v1label, v1props) = vertex.split(/,/, 3)
-    def v1 = graph.addVertex(T.id, v1id.toInteger(), T.label, v1label)
+    def v1 = factory.vertex(v1id.toInteger(), v1label)
     switch (v1label) {
         case "song":
             def (name, songType, performances) = v1props.split(/,/)
@@ -43,8 +43,8 @@ def parse(line, factory) {
             } else {
                 (eLabel, otherV, weight) = parts
             }
-            def v2 = graph.addVertex(T.id, otherV.toInteger())
-            def e = out ? v1.addOutEdge(eLabel, v2) : v1.addInEdge(eLabel, v2)
+            def v2 = factory.vertex(otherV.toInteger())
+            def e = factory.edge(out ? v1 : v2, out ? v2 : v1, eLabel)
             if (weight != null) e.property("weight", weight.toInteger())
         }
     }


[7/9] incubator-tinkerpop git commit: fixed typo

Posted by dk...@apache.org.
fixed typo


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

Branch: refs/heads/tp31
Commit: 3cc0d8a161e50c718cec865d7f7c58705bf95f43
Parents: 19c4197
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed Feb 10 23:30:00 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Wed Feb 10 23:30:00 2016 +0100

----------------------------------------------------------------------
 docs/src/reference/implementations.asciidoc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/3cc0d8a1/docs/src/reference/implementations.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/implementations.asciidoc b/docs/src/reference/implementations.asciidoc
index 5b7e3e4..38c758c 100644
--- a/docs/src/reference/implementations.asciidoc
+++ b/docs/src/reference/implementations.asciidoc
@@ -1544,7 +1544,7 @@ mapper in the Hadoop job. The script must have the following method defined:
 [source,groovy]
 def parse(String line, ScriptElementFactory factory) { ... }
 
-`ScriptElementFactory` is a legacy from previous version and, although it's still functional, it should no longer be used.
+`ScriptElementFactory` is a legacy from previous versions and, although it's still functional, it should no longer be used.
 In order to create vertices and edges, the `parse()` method gets access to a global variable named `graph`, which holds
 the local `StarGraph` for the current line/vertex.
 


[3/9] incubator-tinkerpop git commit: Added ScriptElementFactory::graph() to provide access to the local star graph.

Posted by dk...@apache.org.
Added ScriptElementFactory::graph() to provide access to the local star graph.

This is currently the only option I see that doesn't introduce breaking changes.

Docs and samples were updated accordingly.


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

Branch: refs/heads/tp31
Commit: 99b5791077f14e12dfc61f264c2145d0f3acd0f6
Parents: 50b7f82
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed Feb 10 00:01:31 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Wed Feb 10 00:01:31 2016 +0100

----------------------------------------------------------------------
 data/script-input.groovy                            |  8 ++++----
 docs/src/reference/implementations.asciidoc         |  9 +++++----
 .../io/script/script-input-grateful-dead.groovy     |  9 +++++----
 .../gremlin/structure/io/script/script-input.groovy | 15 +++++++--------
 .../structure/io/script/ScriptRecordReader.java     | 16 ++++++++++++----
 5 files changed, 33 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/99b57910/data/script-input.groovy
----------------------------------------------------------------------
diff --git a/data/script-input.groovy b/data/script-input.groovy
index d2df481..3a2dfd8 100644
--- a/data/script-input.groovy
+++ b/data/script-input.groovy
@@ -17,9 +17,10 @@
  * under the License.
  */
 def parse(line, factory) {
+    def graph = factory.graph()
     def parts = line.split(/ /)
     def (id, label, name, x) = parts[0].split(/:/).toList()
-    def v1 = factory.vertex(id, label)
+    def v1 = graph.addVertex(T.id, id, T.label, label)
     if (name != null) v1.property("name", name) // first value is always the name
     if (x != null) {
         // second value depends on the vertex label; it's either
@@ -30,9 +31,8 @@ def parse(line, factory) {
     if (parts.length == 2) {
         parts[1].split(/,/).grep { !it.isEmpty() }.each {
             def (eLabel, refId, weight) = it.split(/:/).toList()
-            def v2 = factory.vertex(refId)
-            def edge = factory.edge(v1, v2, eLabel)
-            edge.property("weight", Double.valueOf(weight))
+            def v2 = graph.addVertex(T.id, refId)
+            v1.addOutEdge(eLabel, v2, "weight", Double.valueOf(weight))
         }
     }
     return v1

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/99b57910/docs/src/reference/implementations.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/implementations.asciidoc b/docs/src/reference/implementations.asciidoc
index 439123d..5eadef3 100644
--- a/docs/src/reference/implementations.asciidoc
+++ b/docs/src/reference/implementations.asciidoc
@@ -1547,6 +1547,7 @@ def parse(String line, ScriptElementFactory factory) { ... }
 `ScriptElementFactory` provides the following 4 methods:
 
 [source,java]
+Graph graph(); // get a reference to the local star graph
 Vertex vertex(Object id); // get or create the vertex with the given id
 Vertex vertex(Object id, String label); // get or create the vertex with the given id and label
 Edge edge(Vertex out, Vertex in); // create an edge between the two given vertices
@@ -1556,9 +1557,10 @@ An appropriate `parse()` for the above adjacency list file is:
 
 [source,groovy]
 def parse(line, factory) {
+    def graph = factory.graph()
     def parts = line.split(/ /)
     def (id, label, name, x) = parts[0].split(/:/).toList()
-    def v1 = factory.vertex(id, label)
+    def v1 = graph.addVertex(T.id, id, T.label, label)
     if (name != null) v1.property('name', name) // first value is always the name
     if (x != null) {
         // second value depends on the vertex label; it's either
@@ -1569,9 +1571,8 @@ def parse(line, factory) {
     if (parts.length == 2) {
         parts[1].split(/,/).grep { !it.isEmpty() }.each {
             def (eLabel, refId, weight) = it.split(/:/).toList()
-            def v2 = factory.vertex(refId)
-            def edge = factory.edge(v1, v2, eLabel)
-            edge.property('weight', Double.valueOf(weight))
+            def v2 = graph.addVertex(T.id, refId)
+            v1.addOutEdge(eLabel, v2, 'weight', Double.valueOf(weight))
         }
     }
     return v1

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/99b57910/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
index 814843c..9dbc5fc 100644
--- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input-grateful-dead.groovy
@@ -18,9 +18,10 @@
  */
 
 def parse(line, factory) {
+    def graph = factory.graph()
     def (vertex, outEdges, inEdges) = line.split(/\t/, 3)
     def (v1id, v1label, v1props) = vertex.split(/,/, 3)
-    def v1 = factory.vertex(v1id.toInteger(), v1label)
+    def v1 = graph.addVertex(T.id, v1id.toInteger(), T.label, v1label)
     switch (v1label) {
         case "song":
             def (name, songType, performances) = v1props.split(/,/)
@@ -43,10 +44,10 @@ def parse(line, factory) {
             } else {
                 (eLabel, otherV, weight) = parts
             }
-            def v2 = factory.vertex(otherV.toInteger())
-            def e = factory.edge(out ? v1 : v2, out ? v2 : v1, eLabel)
+            def v2 = graph.addVertex(T.id, otherV.toInteger())
+            def e = out ? v1.addOutEdge(eLabel, v2) : v1.addInEdge(eLabel, v2)
             if (weight != null) e.property("weight", weight.toInteger())
         }
     }
     return v1
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/99b57910/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy
index adb32b7..096fdd4 100644
--- a/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy
+++ b/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/script/script-input.groovy
@@ -19,9 +19,10 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty
  * under the License.
  */
 def parse(line, factory) {
+    def graph = factory.graph()
     def parts = line.split(/\t/)
     def (id, label, name, x) = parts[0].split(/:/).toList()
-    def v1 = factory.vertex(id, label)
+    def v1 = graph.addVertex(T.id, id, T.label, label)
     if (name != null) v1.property(VertexProperty.Cardinality.single, "name", name)
     if (x != null) {
         if (label.equals("project")) v1.property(VertexProperty.Cardinality.single, "lang", x)
@@ -31,19 +32,17 @@ def parse(line, factory) {
     if (parts.length >= 2) {
         parts[1].split(/,/).grep { !it.isEmpty() }.each {
             def (eLabel, refId, weight) = it.split(/:/).toList()
-            def v2 = factory.vertex(refId)
-            def edge = factory.edge(v1, v2, eLabel)
-            edge.property("weight", Double.valueOf(weight))
+            def v2 = graph.addVertex(T.id, refId)
+            v1.addOutEdge(eLabel, v2, "weight", Double.valueOf(weight))
         }
     }
     // process in-edges
     if (parts.length == 3) {
         parts[2].split(/,/).grep { !it.isEmpty() }.each {
             def (eLabel, refId, weight) = it.split(/:/).toList()
-            def v2 = factory.vertex(refId)
-            def edge = factory.edge(v2, v1, eLabel)
-            edge.property("weight", Double.valueOf(weight))
+            def v2 = graph.addVertex(T.id, refId)
+            v1.addInEdge(eLabel, v2, "weight", Double.valueOf(weight))
         }
     }
     return v1
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/99b57910/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
index 4cc1602..4615b51 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
@@ -39,6 +39,7 @@ import javax.script.Bindings;
 import javax.script.ScriptEngine;
 import javax.script.ScriptException;
 import java.io.IOException;
+import java.io.InputStream;
 import java.io.InputStreamReader;
 import java.util.Iterator;
 
@@ -68,10 +69,13 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
         this.engine = new GremlinGroovyScriptEngine((CompilerCustomizerProvider) new DefaultImportCustomizerProvider());
         //this.engine = ScriptEngineCache.get(configuration.get(SCRIPT_ENGINE, ScriptEngineCache.DEFAULT_SCRIPT_ENGINE));
         final FileSystem fs = FileSystem.get(configuration);
-        try {
-            this.engine.eval(new InputStreamReader(fs.open(new Path(configuration.get(SCRIPT_FILE)))));
-        } catch (final ScriptException e) {
-            throw new IOException(e.getMessage(), e);
+        try (final InputStream stream = fs.open(new Path(configuration.get(SCRIPT_FILE)));
+             final InputStreamReader reader = new InputStreamReader(stream)) {
+            try {
+                this.engine.eval(reader);
+            } catch (ScriptException e) {
+                throw new IOException(e.getMessage(), e);
+            }
         }
     }
 
@@ -138,5 +142,9 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
         public Edge edge(final Vertex out, final Vertex in, final String label) {
             return out.addEdge(label, in);
         }
+
+        public StarGraph graph() {
+            return this.graph;
+        }
     }
 }


[2/9] incubator-tinkerpop git commit: Revert "Added another `edge()` method in `ScriptElementFactory` that allows to set explicit edge ids."

Posted by dk...@apache.org.
Revert "Added another `edge()` method in `ScriptElementFactory` that allows to set explicit edge ids."

This reverts commit 50d5dd9bdb52633d9655f5a476f9885e6ff298d7.


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

Branch: refs/heads/tp31
Commit: 50b7f82883fa2d92b04efa8b7d537e2399865e06
Parents: 50d5dd9
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Tue Feb 9 21:12:19 2016 +0100
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Tue Feb 9 21:12:19 2016 +0100

----------------------------------------------------------------------
 docs/src/reference/implementations.asciidoc                      | 1 -
 .../gremlin/hadoop/structure/io/script/ScriptRecordReader.java   | 4 ----
 2 files changed, 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/50b7f828/docs/src/reference/implementations.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/implementations.asciidoc b/docs/src/reference/implementations.asciidoc
index 6b29ae7..439123d 100644
--- a/docs/src/reference/implementations.asciidoc
+++ b/docs/src/reference/implementations.asciidoc
@@ -1551,7 +1551,6 @@ Vertex vertex(Object id); // get or create the vertex with the given id
 Vertex vertex(Object id, String label); // get or create the vertex with the given id and label
 Edge edge(Vertex out, Vertex in); // create an edge between the two given vertices
 Edge edge(Vertex out, Vertex in, String label); // create an edge between the two given vertices using the given label
-Edge edge(Vertex out, Vertex in, Object id, String label); // create an edge between the two given vertices using the given edge id and label
 
 An appropriate `parse()` for the above adjacency list file is:
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/50b7f828/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
----------------------------------------------------------------------
diff --git a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
index b5e1cc0..4cc1602 100644
--- a/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
+++ b/hadoop-gremlin/src/main/java/org/apache/tinkerpop/gremlin/hadoop/structure/io/script/ScriptRecordReader.java
@@ -138,9 +138,5 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW
         public Edge edge(final Vertex out, final Vertex in, final String label) {
             return out.addEdge(label, in);
         }
-
-        public Edge edge(final Vertex out, final Vertex in, final Object id, final String label) {
-            return out.addEdge(label, in, T.id, id);
-        }
     }
 }