Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions data/script-input.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions docs/src/reference/implementations-hadoop-end.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -337,4 +336,4 @@ Vertex 4 ("josh") is isolated below:
"age":[{"id":7,"value":32}]}
}
}
----
----
Original file line number Diff line number Diff line change
Expand Up @@ -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(/,/)
Expand All @@ -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())
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -86,8 +84,8 @@ public void initialize(final InputSplit genericSplit, final TaskAttemptContext c
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);
}
Expand All @@ -100,10 +98,8 @@ public boolean nextKeyValue() throws IOException {
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);
Expand Down Expand Up @@ -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<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);
}
}
}