Repository: tinkerpop Updated Branches: refs/heads/master 86edf56e9 -> cad76a816
Removed previously deprecated `ScriptElementFactory`. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/cad76a81 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/cad76a81 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/cad76a81 Branch: refs/heads/master Commit: cad76a8169fa67fb56d35f17721274abfc82dfce Parents: 86edf56 Author: Daniel Kuppitz <[email protected]> Authored: Mon Jul 31 18:31:33 2017 +0200 Committer: Daniel Kuppitz <[email protected]> Committed: Tue Aug 1 18:06:51 2017 +0200 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + data/script-input.groovy | 4 +- .../implementations-hadoop-end.asciidoc | 7 ++-- .../io/script/script-input-grateful-dead.groovy | 8 ++-- .../structure/io/script/script-input.groovy | 2 +- .../structure/io/script/ScriptRecordReader.java | 41 ++------------------ 6 files changed, 13 insertions(+), 50 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cad76a81/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index cbf0621..09476a0 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima TinkerPop 3.3.0 (Release Date: NOT OFFICIALLY RELEASED YET) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +* Removed previously deprecated `ScriptElementFactory`. * Bumped to support Giraph 1.2.0. * Bumped to support Spark 2.2.0. * Detected if type checking was required in `GremlinGroovyScriptEngine` and disabled related infrastructure if not. http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cad76a81/data/script-input.groovy ---------------------------------------------------------------------- diff --git a/data/script-input.groovy b/data/script-input.groovy index 4e1d219..b111cce 100644 --- a/data/script-input.groovy +++ b/data/script-input.groovy @@ -16,9 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -def parse(line, factory) { - // "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 parse(line) { 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/tinkerpop/blob/cad76a81/docs/src/reference/implementations-hadoop-end.asciidoc ---------------------------------------------------------------------- diff --git a/docs/src/reference/implementations-hadoop-end.asciidoc b/docs/src/reference/implementations-hadoop-end.asciidoc index 3fe768d..1855b16 100644 --- a/docs/src/reference/implementations-hadoop-end.asciidoc +++ b/docs/src/reference/implementations-hadoop-end.asciidoc @@ -91,16 +91,15 @@ As such, `ScriptInputFormat` can be used. With `ScriptInputFormat` a script is s mapper in the Hadoop job. The script must have the following method defined: [source,groovy] -def parse(String line, ScriptElementFactory factory) { ... } +def parse(String line) { ... } -`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. An appropriate `parse()` for the above adjacency list file is: [source,groovy] -def parse(line, factory) { +def parse(line) { def parts = line.split(/ /) def (id, label, name, x) = parts[0].split(/:/).toList() def v1 = graph.addVertex(T.id, id, T.label, label) @@ -337,4 +336,4 @@ Vertex 4 ("josh") is isolated below: "age":[{"id":7,"value":32}]} } } ----- \ No newline at end of file +---- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cad76a81/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 b334207..ca3eb6e 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 @@ -17,10 +17,10 @@ * under the License. */ -def parse(line, factory) { +def parse(line) { 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,8 +43,8 @@ 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()) } } http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/cad76a81/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 991aef3..d7dd46e 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 @@ -18,7 +18,7 @@ import org.apache.tinkerpop.gremlin.structure.VertexProperty * specific language governing permissions and limitations * under the License. */ -def parse(line, factory) { +def parse(line) { 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/tinkerpop/blob/cad76a81/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 3299c1c..7dd4e2b 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 @@ -60,14 +60,12 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW 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 static String READ_CALL = "parse(" + LINE + ")"; private final VertexWritable vertexWritable = new VertexWritable(); private final LineRecordReader lineRecordReader; private final GremlinScriptEngineManager manager = new CachedGremlinScriptEngineManager(); private ScriptEngine engine; - private String parse; private CompiledScript script; private GraphFilter graphFilter = new GraphFilter(); @@ -86,8 +84,8 @@ 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)) { - this.parse = String.join("\n", IOUtils.toString(reader), READ_CALL); - script = ((Compilable) engine).compile(this.parse); + final String parse = String.join("\n", IOUtils.toString(reader), READ_CALL); + script = ((Compilable) engine).compile(parse); } catch (ScriptException e) { throw new IOException(e.getMessage(), e); } @@ -100,10 +98,8 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW 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, factory); final StarGraph.StarVertex sv = (StarGraph.StarVertex) script.eval(bindings); if (sv != null) { final Optional<StarGraph.StarVertex> vertex = sv.applyGraphFilter(this.graphFilter); @@ -137,35 +133,4 @@ public final class ScriptRecordReader extends RecordReader<NullWritable, VertexW public synchronized void close() throws IOException { this.lineRecordReader.close(); } - - @Deprecated - protected class ScriptElementFactory { - - private final StarGraph graph; - - public ScriptElementFactory() { - this(StarGraph.open()); - } - - public ScriptElementFactory(final StarGraph graph) { - this.graph = graph; - } - - public Vertex vertex(final Object id) { - return vertex(id, Vertex.DEFAULT_LABEL); - } - - public Vertex vertex(final Object id, final String label) { - final Iterator<Vertex> vertices = graph.vertices(id); - return vertices.hasNext() ? vertices.next() : graph.addVertex(T.id, id, T.label, label); - } - - public Edge edge(final Vertex out, final Vertex in) { - return edge(out, in, Edge.DEFAULT_LABEL); - } - - public Edge edge(final Vertex out, final Vertex in, final String label) { - return out.addEdge(label, in); - } - } }
