From cad76a8169fa67fb56d35f17721274abfc82dfce Mon Sep 17 00:00:00 2001 From: Daniel Kuppitz Date: Mon, 31 Jul 2017 18:31:33 +0200 Subject: [PATCH] Removed previously deprecated `ScriptElementFactory`. --- CHANGELOG.asciidoc | 1 + data/script-input.groovy | 4 +- .../implementations-hadoop-end.asciidoc | 7 ++-- .../script/script-input-grateful-dead.groovy | 8 ++-- .../structure/io/script/script-input.groovy | 2 +- .../io/script/ScriptRecordReader.java | 41 ++----------------- 6 files changed, 13 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index cbf06213ded..09476a0dbaf 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. diff --git a/data/script-input.groovy b/data/script-input.groovy index 4e1d219f7f4..b111ccef7f3 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) diff --git a/docs/src/reference/implementations-hadoop-end.asciidoc b/docs/src/reference/implementations-hadoop-end.asciidoc index 3fe768d1af1..1855b165ec6 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 +---- 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 b334207b8e9..ca3eb6ecf7e 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()) } } 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 991aef3e292..d7dd46ea0d2 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) 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 3299c1c985b..7dd4e2b1536 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 vertex = sv.applyGraphFilter(this.graphFilter); @@ -137,35 +133,4 @@ public float getProgress() throws IOException { 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 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); - } - } }