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/10 16:29:29 UTC

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

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1137 99b579107 -> 19c419731


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/TINKERPOP-1137
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;
-        }
     }
 }


[3/3] 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/TINKERPOP-1137
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)


[2/3] 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/TINKERPOP-1137
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.