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:42:26 UTC
[04/10] incubator-tinkerpop git commit: Marked `ScriptElementFactory`
as deprecated and made the local star graph globally available for the
ScriptInputFormat's user defined parse() method.
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/master
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;
- }
}
}