You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/10/07 20:58:45 UTC
[6/7] tinkerpop git commit: okay,
this is the gold. withComputer() is now smart about just redirecting
to withStrategies(VertexProgramStrategy). This way Computer doesn't need to
be a first class citizen and supported with a serializer by the various lan
okay, this is the gold. withComputer() is now smart about just redirecting to withStrategies(VertexProgramStrategy). This way Computer doesn't need to be a first class citizen and supported with a serializer by the various language variants. Also, this is much much more consistent --- its all just strategies. Got Gremlin-Python strategies all implemented and working nicely. This is a really cool thing. Updated docs and CHANGELOG.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6fdc59d2
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6fdc59d2
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6fdc59d2
Branch: refs/heads/master
Commit: 6fdc59d20e6e7a2aad54b55db343e74907e0c652
Parents: f84b196
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Oct 7 12:44:31 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Oct 7 12:44:31 2016 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
docs/preprocessor/awk/init-code-blocks.awk | 1 +
docs/src/reference/gremlin-variants.asciidoc | 7 +-
.../gremlin/process/computer/Computer.java | 51 ------
.../decoration/VertexProgramStrategy.java | 161 ++++++++++++++++++-
.../computer/util/GraphComputerHelper.java | 8 +-
.../gremlin/process/traversal/Bytecode.java | 4 -
.../process/traversal/TraversalSource.java | 44 ++---
.../dsl/graph/GraphTraversalSource.java | 7 +-
.../gremlin/process/traversal/BytecodeTest.java | 6 +-
.../gremlin/groovy/jsr223/GroovyTranslator.java | 5 +-
.../python/GraphTraversalSourceGenerator.groovy | 6 +-
.../gremlin/python/jsr223/PythonTranslator.java | 3 -
.../gremlin_python/process/graph_traversal.py | 7 +-
.../jython/gremlin_python/process/strategies.py | 57 +++++--
.../driver/test_driver_remote_connection.py | 2 +-
.../jython/tests/structure/io/test_graphson.py | 2 +-
.../process/TinkerGraphComputerProvider.java | 10 +-
18 files changed, 252 insertions(+), 130 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 2fbc9a0..9475555 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
TinkerPop 3.2.3 (Release Date: NOT OFFICIALLY RELEASED YET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+* `TraversalSource.withComputer()` is simplified to add a `VertexProgramStrategy`. Easier for language variants.
* Fixed a `Set`, `List`, `Map` bug in the various `Translators` where such collections were not being internally translated.
* Fixed a `Bytecode` bug where nested structures (map, list, set) were not being analyzed for bindings and bytecode conversions.
* Fixed a `String` bug in `GroovyTranslator` and `PythonTranslator` where if the string has double-quotes it now uses """ """.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/docs/preprocessor/awk/init-code-blocks.awk
----------------------------------------------------------------------
diff --git a/docs/preprocessor/awk/init-code-blocks.awk b/docs/preprocessor/awk/init-code-blocks.awk
index 2b66eaf..f9b020a 100644
--- a/docs/preprocessor/awk/init-code-blocks.awk
+++ b/docs/preprocessor/awk/init-code-blocks.awk
@@ -60,6 +60,7 @@ BEGIN {
print "jython.eval('sys.path.append(\"" TP_HOME "/gremlin-python/target/test-classes/Lib\")')"
print "jython.eval('from gremlin_python import statics')"
print "jython.eval('from gremlin_python.process.traversal import *')"
+ print "jython.eval('from gremlin_python.process.strategies import *')"
print "jython.eval('from gremlin_python.structure.graph import Graph')"
print "jython.eval('from gremlin_python.structure.io.graphson import GraphSONWriter')"
print "jython.eval('from gremlin_python.structure.io.graphson import GraphSONReader')"
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 51e2d2b..0716ff1 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -62,7 +62,7 @@ Gremlin-Python users will typically make use of the following classes.
>>> from gremlin_python import statics
>>> from gremlin_python.structure.graph import Graph
>>> from gremlin_python.process.graph_traversal import __
->>> from gremlin_python.process.traversal import TraversalStrategy
+>>> from gremlin_python.process.strategies import *
>>> from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
In Gremlin-Python there exists `GraphTraversalSource`, `GraphTraversal`, and `__` which mirror the respective classes in Gremlin-Java.
@@ -239,11 +239,14 @@ g.V().outE().valueMap(True).toList()
g = g.withoutStrategies(SubgraphStrategy)
g.V().name.toList()
g.V().outE().valueMap(True).toList()
+g = g.withComputer(workers=2,vertices=has('name','marko'))
+g.V().name.toList()
+g.V().outE().valueMap(True).toList()
----
NOTE: Many of the `TraversalStrategy` classes in Gremlin-Python are proxies to the respective strategy on the
Apache TinkerPop's JVM-based Gremlin traversal machine. As such, their `apply(Traversal)` method does nothing. However,
-the strategy is encoded in the Gremlin-Python bytecode and transmittable to the Gremlin traversal machine for
+the strategy is encoded in the Gremlin-Python bytecode and transmitted to the Gremlin traversal machine for
re-construction machine-side.
The Lambda Solution
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Computer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Computer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Computer.java
index 86e1a12..a82b4e6 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Computer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/Computer.java
@@ -46,13 +46,6 @@ public final class Computer implements Function<Graph, GraphComputer>, Serializa
private Traversal<Vertex, Vertex> vertices = null;
private Traversal<Vertex, Edge> edges = null;
- public static final String GRAPH_COMPUTER = "graphComputer";
- public static final String WORKERS = "workers";
- public static final String PERSIST = "persist";
- public static final String RESULT = "result";
- public static final String VERTICES = "vertices";
- public static final String EDGES = "edges";
-
private Computer(final Class<? extends GraphComputer> graphComputerClass) {
this.graphComputerClass = graphComputerClass;
}
@@ -60,32 +53,6 @@ public final class Computer implements Function<Graph, GraphComputer>, Serializa
private Computer() {
}
-
- public static Computer compute(final Configuration configuration) {
- try {
- final Computer computer = new Computer();
- for (final String key : (List<String>) IteratorUtils.asList(configuration.getKeys())) {
- if (key.equals(GRAPH_COMPUTER))
- computer.graphComputerClass = (Class) Class.forName(configuration.getString(key));
- else if (key.equals(WORKERS))
- computer.workers = configuration.getInt(key);
- else if (key.equals(PERSIST))
- computer.persist = GraphComputer.Persist.valueOf(configuration.getString(key));
- else if (key.equals(RESULT))
- computer.resultGraph = GraphComputer.ResultGraph.valueOf(configuration.getString(key));
- else if (key.equals(VERTICES))
- computer.vertices = (Traversal) configuration.getProperty(key);
- else if (key.equals(EDGES))
- computer.edges = (Traversal) configuration.getProperty(key);
- else
- computer.configuration.put(key, configuration.getProperty(key));
- }
- return computer;
- } catch (final ClassNotFoundException e) {
- throw new IllegalArgumentException(e.getMessage(), e);
- }
- }
-
public static Computer compute() {
return new Computer(GraphComputer.class);
}
@@ -200,22 +167,4 @@ public final class Computer implements Function<Graph, GraphComputer>, Serializa
return this.workers;
}
- public Configuration getConf() {
- final Map<String, Object> map = new HashMap<>();
- if (-1 != this.workers)
- map.put(WORKERS, this.workers);
- if (null != this.persist)
- map.put(PERSIST, this.persist.name());
- if (null != this.resultGraph)
- map.put(RESULT, this.resultGraph.name());
- if (null != this.vertices)
- map.put(RESULT, this.vertices);
- if (null != this.edges)
- map.put(EDGES, this.edges);
- map.put(GRAPH_COMPUTER, this.graphComputerClass.getCanonicalName());
- for (final Map.Entry<String, Object> entry : this.configuration.entrySet()) {
- map.put(entry.getKey(), entry.getValue());
- }
- return new MapConfiguration(map);
- }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategy.java
index 0496ae3..42f9bef 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/traversal/strategy/decoration/VertexProgramStrategy.java
@@ -19,7 +19,10 @@
package org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration;
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.MapConfiguration;
import org.apache.tinkerpop.gremlin.process.computer.Computer;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.computer.traversal.step.VertexComputing;
import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ComputerResultStep;
import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.ProgramVertexProgramStep;
@@ -35,8 +38,14 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.Set;
@@ -45,14 +54,44 @@ import java.util.Set;
*/
public final class VertexProgramStrategy extends AbstractTraversalStrategy<TraversalStrategy.DecorationStrategy> implements TraversalStrategy.DecorationStrategy {
+ private final Class<? extends GraphComputer> graphComputerClass;
+ private final Map<String, Object> configuration;
+ private final int workers;
+ private final GraphComputer.Persist persist;
+ private final GraphComputer.ResultGraph resultGraph;
+ private final Traversal<Vertex, Vertex> vertices;
+ private final Traversal<Vertex, Edge> edges;
private Computer computer;
+
private VertexProgramStrategy() {
+ this(null, -1, null, null, null, null, null);
}
public VertexProgramStrategy(final Computer computer) {
- this.computer = computer;
+ this(computer.getGraphComputerClass(), computer.getWorkers(), computer.getResultGraph(), computer.getPersist(), computer.getVertices(), computer.getEdges(), computer.getConfiguration());
+ }
+
+ public VertexProgramStrategy(final Class<? extends GraphComputer> graphComputerClass, final int workers,
+ final GraphComputer.ResultGraph result, final GraphComputer.Persist persist,
+ final Traversal<Vertex, Vertex> vertices, final Traversal<Vertex, Edge> edges,
+ final Map<String, Object> configuration) {
+ this.graphComputerClass = graphComputerClass;
+ this.workers = workers;
+ this.resultGraph = result;
+ this.persist = persist;
+ this.vertices = vertices;
+ this.edges = edges;
+ this.configuration = configuration;
+ this.computer = Computer.compute(this.graphComputerClass).workers(this.workers).result(this.resultGraph).persist(this.persist).vertices(this.vertices).edges(this.edges);
+ for (final Map.Entry<String, Object> entry : this.configuration.entrySet()) {
+ this.computer = this.computer.configure(entry.getKey(), entry.getValue());
+ }
+ }
+
+ public Computer getComputer() {
+ return this.computer;
}
@Override
@@ -148,4 +187,124 @@ public final class VertexProgramStrategy extends AbstractTraversalStrategy<Trave
final Optional<TraversalStrategy<?>> optional = strategies.toList().stream().filter(strategy -> strategy instanceof VertexProgramStrategy).findAny();
return optional.isPresent() ? Optional.of(((VertexProgramStrategy) optional.get()).computer) : Optional.empty();
}
+
+ ////////////////////////////////////////////////////////////
+
+ public static final String GRAPH_COMPUTER = "graphComputer";
+ public static final String WORKERS = "workers";
+ public static final String PERSIST = "persist";
+ public static final String RESULT = "result";
+ public static final String VERTICES = "vertices";
+ public static final String EDGES = "edges";
+
+ public static VertexProgramStrategy create(final Configuration configuration) {
+ try {
+ final VertexProgramStrategy.Builder builder = VertexProgramStrategy.build();
+ for (final String key : (List<String>) IteratorUtils.asList(configuration.getKeys())) {
+ if (key.equals(GRAPH_COMPUTER))
+ builder.graphComputerClass = (Class) Class.forName(configuration.getString(key));
+ else if (key.equals(WORKERS))
+ builder.workers = configuration.getInt(key);
+ else if (key.equals(PERSIST))
+ builder.persist = GraphComputer.Persist.valueOf(configuration.getString(key));
+ else if (key.equals(RESULT))
+ builder.resultGraph = GraphComputer.ResultGraph.valueOf(configuration.getString(key));
+ else if (key.equals(VERTICES))
+ builder.vertices = (Traversal) configuration.getProperty(key);
+ else if (key.equals(EDGES))
+ builder.edges = (Traversal) configuration.getProperty(key);
+ else
+ builder.configuration.put(key, configuration.getProperty(key));
+ }
+ return builder.create();
+ } catch (final ClassNotFoundException e) {
+ throw new IllegalArgumentException(e.getMessage(), e);
+ }
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ final Map<String, Object> map = new HashMap<>();
+ map.put(GRAPH_COMPUTER, this.graphComputerClass.getCanonicalName());
+ if (-1 != this.workers)
+ map.put(WORKERS, this.workers);
+ if (null != this.persist)
+ map.put(PERSIST, this.persist.name());
+ if (null != this.resultGraph)
+ map.put(RESULT, this.resultGraph.name());
+ if (null != this.vertices)
+ map.put(VERTICES, this.vertices);
+ if (null != this.edges)
+ map.put(EDGES, this.edges);
+ for (final Map.Entry<String, Object> entry : this.configuration.entrySet()) {
+ map.put(entry.getKey(), entry.getValue());
+ }
+ return new MapConfiguration(map);
+ }
+
+ public static Builder build() {
+ return new Builder();
+ }
+
+ public final static class Builder {
+
+ private Class<? extends GraphComputer> graphComputerClass = GraphComputer.class;
+ private Map<String, Object> configuration = new HashMap<>();
+ private int workers = -1;
+ private GraphComputer.Persist persist = null;
+ private GraphComputer.ResultGraph resultGraph = null;
+ private Traversal<Vertex, Vertex> vertices = null;
+ private Traversal<Vertex, Edge> edges = null;
+
+ private Builder() {
+ }
+
+ public Builder graphComputer(final Class<? extends GraphComputer> graphComputerClass) {
+ this.graphComputerClass = graphComputerClass;
+ return this;
+ }
+
+ public Builder configure(final String key, final Object value) {
+ this.configuration.put(key, value);
+ return this;
+ }
+
+ public Builder configure(final Map<String, Object> configurations) {
+ for (final Map.Entry<String, Object> entry : configurations.entrySet()) {
+ this.configuration.put(entry.getKey(), entry.getValue());
+ }
+ return this;
+ }
+
+ public Builder workers(final int workers) {
+ this.workers = workers;
+ return this;
+ }
+
+ public Builder persist(final GraphComputer.Persist persist) {
+ this.persist = persist;
+ return this;
+ }
+
+
+ public Builder result(final GraphComputer.ResultGraph resultGraph) {
+ this.resultGraph = resultGraph;
+ return this;
+ }
+
+ public Builder vertices(final Traversal<Vertex, Vertex> vertices) {
+ this.vertices = vertices;
+ return this;
+ }
+
+ public Builder edges(final Traversal<Vertex, Edge> edges) {
+ this.edges = edges;
+ return this;
+ }
+
+ public VertexProgramStrategy create() {
+ return new VertexProgramStrategy(this.graphComputerClass, this.workers, this.resultGraph, this.persist, this.vertices, this.edges, this.configuration);
+ }
+ }
+
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/GraphComputerHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/GraphComputerHelper.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/GraphComputerHelper.java
index 5787681..f624545 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/GraphComputerHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/util/GraphComputerHelper.java
@@ -84,7 +84,8 @@ public final class GraphComputerHelper {
return a.getClass().equals(b.getClass()) && a.getMemoryKey().equals(((MapReduce) b).getMemoryKey());
}
- public static TraversalStrategy[] getTraversalStrategies(final TraversalSource traversalSource, final Computer computer) {
+ public static TraversalStrategy[] getTraversalStrategies(final TraversalSource traversalSource, final VertexProgramStrategy vertexProgramStrategy) {
+ final Computer computer = vertexProgramStrategy.getComputer();
Class<? extends GraphComputer> graphComputerClass;
if (computer.getGraphComputerClass().equals(GraphComputer.class)) {
try {
@@ -95,10 +96,9 @@ public final class GraphComputerHelper {
} else
graphComputerClass = computer.getGraphComputerClass();
final List<TraversalStrategy<?>> graphComputerStrategies = TraversalStrategies.GlobalCache.getStrategies(graphComputerClass).toList();
- final TraversalStrategy[] traversalStrategies = new TraversalStrategy[graphComputerStrategies.size() + 1];
- traversalStrategies[0] = new VertexProgramStrategy(computer);
+ final TraversalStrategy[] traversalStrategies = new TraversalStrategy[graphComputerStrategies.size()];
for (int i = 0; i < graphComputerStrategies.size(); i++) {
- traversalStrategies[i + 1] = graphComputerStrategies.get(i);
+ traversalStrategies[i] = graphComputerStrategies.get(i);
}
return traversalStrategies;
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
index d2ca5cb..da09362 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/Bytecode.java
@@ -19,8 +19,6 @@
package org.apache.tinkerpop.gremlin.process.traversal;
-import org.apache.commons.configuration.ConfigurationConverter;
-import org.apache.tinkerpop.gremlin.process.computer.Computer;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.TraversalStrategyProxy;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
@@ -283,8 +281,6 @@ public final class Bytecode implements Cloneable, Serializable {
//
if (argument instanceof Traversal)
return ((Traversal) argument).asAdmin().getBytecode();
- else if (argument instanceof Computer)
- return convertArgument(ConfigurationConverter.getMap(((Computer) argument).getConf()), true);
else if (argument instanceof Map) {
final Map<Object, Object> map = new LinkedHashMap<>(((Map) argument).size());
for (final Map.Entry<?, ?> entry : ((Map<?, ?>) argument).entrySet()) {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
index fa697f6..0185a33 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
@@ -19,7 +19,6 @@
package org.apache.tinkerpop.gremlin.process.traversal;
import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.MapConfiguration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.tinkerpop.gremlin.process.computer.Computer;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
@@ -33,7 +32,6 @@ import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
import java.io.Serializable;
import java.lang.reflect.Constructor;
-import java.util.Map;
import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
@@ -108,6 +106,12 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
final TraversalSource clone = this.clone();
clone.getStrategies().addStrategies(traversalStrategies);
clone.getBytecode().addSource(TraversalSource.Symbols.withStrategies, traversalStrategies);
+ for (final TraversalStrategy traversalStrategy : traversalStrategies) {
+ if (traversalStrategy instanceof VertexProgramStrategy) {
+ clone.getStrategies().addStrategies(GraphComputerHelper.getTraversalStrategies(this, (VertexProgramStrategy) traversalStrategy));
+ break;
+ }
+ }
return clone;
}
@@ -139,20 +143,6 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
}
/**
- * Configure a {@link GraphComputer} to be used for the execution of subsequently spawned traversal.
- * This adds a {@link VertexProgramStrategy} to the strategies.
- *
- * @param computerConfiguration key/value pair map for configuring a {@link Computer}
- * @return a new traversal source with updated strategies
- */
- public default TraversalSource withComputer(final Map<String, Object> computerConfiguration) {
- final TraversalSource clone = this.clone();
- clone.getStrategies().addStrategies(GraphComputerHelper.getTraversalStrategies(this, Computer.compute(new MapConfiguration(computerConfiguration))));
- clone.getBytecode().addSource(TraversalSource.Symbols.withComputer, computerConfiguration);
- return clone;
- }
-
- /**
* Add a {@link Computer} that will generate a {@link GraphComputer} from the {@link Graph} that will be used to execute the traversal.
* This adds a {@link VertexProgramStrategy} to the strategies.
*
@@ -160,10 +150,14 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
* @return a new traversal source with updated strategies
*/
public default TraversalSource withComputer(final Computer computer) {
- final TraversalSource clone = this.clone();
- clone.getStrategies().addStrategies(GraphComputerHelper.getTraversalStrategies(this, computer));
- clone.getBytecode().addSource(TraversalSource.Symbols.withComputer, computer);
- return clone;
+ return this.withStrategies(VertexProgramStrategy.build().
+ graphComputer(computer.getGraphComputerClass()).
+ workers(computer.getWorkers()).
+ result(computer.getResultGraph()).
+ persist(computer.getPersist()).
+ vertices(computer.getVertices()).
+ edges(computer.getEdges()).
+ configure(computer.getConfiguration()).create());
}
/**
@@ -174,10 +168,7 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
* @return a new traversal source with updated strategies
*/
public default TraversalSource withComputer(final Class<? extends GraphComputer> graphComputerClass) {
- final TraversalSource clone = this.clone();
- clone.getStrategies().addStrategies(GraphComputerHelper.getTraversalStrategies(this, Computer.compute(graphComputerClass)));
- clone.getBytecode().addSource(TraversalSource.Symbols.withComputer, graphComputerClass);
- return clone;
+ return this.withStrategies(VertexProgramStrategy.build().graphComputer(graphComputerClass).create());
}
/**
@@ -187,10 +178,7 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
* @return a new traversal source with updated strategies
*/
public default TraversalSource withComputer() {
- final TraversalSource clone = this.clone();
- clone.getStrategies().addStrategies(GraphComputerHelper.getTraversalStrategies(this, Computer.compute()));
- clone.getBytecode().addSource(TraversalSource.Symbols.withComputer);
- return clone;
+ return this.withStrategies(VertexProgramStrategy.build().create());
}
/**
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
index 4cf20ce..362c571 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSource.java
@@ -137,12 +137,7 @@ public class GraphTraversalSource implements TraversalSource {
public GraphTraversalSource withBindings(final Bindings bindings) {
return (GraphTraversalSource) TraversalSource.super.withBindings(bindings);
}
-
- @Override
- public GraphTraversalSource withComputer(final Map<String,Object> computerConfiguration) {
- return (GraphTraversalSource) TraversalSource.super.withComputer(computerConfiguration);
- }
-
+
@Override
public GraphTraversalSource withComputer(final Computer computer) {
return (GraphTraversalSource) TraversalSource.super.withComputer(computer);
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java
index e6df371..1b655ca 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/BytecodeTest.java
@@ -19,8 +19,8 @@
package org.apache.tinkerpop.gremlin.process.traversal;
-import org.apache.commons.configuration.ConfigurationConverter;
import org.apache.tinkerpop.gremlin.process.computer.Computer;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
@@ -112,6 +112,8 @@ public class BytecodeTest {
public void shouldConvertComputer() {
final GraphTraversalSource g = EmptyGraph.instance().traversal();
Bytecode bytecode = g.withComputer(Computer.compute().workers(10)).getBytecode();
- assertEquals(ConfigurationConverter.getMap(Computer.compute().workers(10).getConf()), bytecode.getSourceInstructions().iterator().next().getArguments()[0]);
+ assertEquals(VertexProgramStrategy.build().create(), bytecode.getSourceInstructions().iterator().next().getArguments()[0]);
+ assertEquals(VertexProgramStrategy.build().workers(10).create().getConfiguration().getInt(VertexProgramStrategy.WORKERS),
+ ((VertexProgramStrategy) bytecode.getSourceInstructions().iterator().next().getArguments()[0]).getConfiguration().getInt(VertexProgramStrategy.WORKERS));
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
index 3d2aece..02e49b1 100644
--- a/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
+++ b/gremlin-groovy/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslator.java
@@ -20,7 +20,6 @@
package org.apache.tinkerpop.gremlin.groovy.jsr223;
import org.apache.commons.configuration.ConfigurationConverter;
-import org.apache.tinkerpop.gremlin.process.computer.Computer;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
@@ -159,9 +158,7 @@ public final class GroovyTranslator implements Translator.ScriptTranslator {
else if (object instanceof Lambda) {
final String lambdaString = ((Lambda) object).getLambdaScript().trim();
return lambdaString.startsWith("{") ? lambdaString : "{" + lambdaString + "}";
- } else if (object instanceof Computer)
- return convertToString(ConfigurationConverter.getMap(((Computer) object).getConf()));
- else if (object instanceof TraversalStrategyProxy) {
+ } else if (object instanceof TraversalStrategyProxy) {
final TraversalStrategyProxy proxy = (TraversalStrategyProxy) object;
if (proxy.getConfiguration().isEmpty())
return proxy.getStrategyClass().getCanonicalName() + ".instance()";
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
index cdca686..ed377bd 100644
--- a/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
+++ b/gremlin-python/src/main/groovy/org/apache/tinkerpop/gremlin/python/GraphTraversalSourceGenerator.groovy
@@ -58,6 +58,7 @@ under the License.
pythonClass.append("import sys\n")
pythonClass.append("from .traversal import Traversal\n")
pythonClass.append("from .traversal import TraversalStrategies\n")
+ pythonClass.append("from .strategies import VertexProgramStrategy\n")
pythonClass.append("from .traversal import Bytecode\n")
pythonClass.append("from ..driver.remote_connection import RemoteStrategy\n")
pythonClass.append("from .. import statics\n")
@@ -82,7 +83,8 @@ under the License.
findAll {
!it.name.equals("clone") &&
!it.name.equals(TraversalSource.Symbols.withBindings) &&
- !it.name.equals(TraversalSource.Symbols.withRemote)
+ !it.name.equals(TraversalSource.Symbols.withRemote) &&
+ !it.name.equals(TraversalSource.Symbols.withComputer)
}.
collect { SymbolHelper.toPython(it.name) }.
unique().
@@ -102,6 +104,8 @@ under the License.
return source
def withBindings(self, bindings):
return self
+ def withComputer(self,graph_computer=None, workers=None, result=None, persist=None, vertices=None, edges=None, configuration=None):
+ return self.withStrategies(VertexProgramStrategy(graph_computer,workers,result,persist,vertices,edges,configuration))
""")
GraphTraversalSource.getMethods(). // SPAWN STEPS
findAll { GraphTraversal.class.equals(it.returnType) }.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
index 9219717..bfabbb8 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonTranslator.java
@@ -20,7 +20,6 @@
package org.apache.tinkerpop.gremlin.python.jsr223;
import org.apache.commons.configuration.ConfigurationConverter;
-import org.apache.tinkerpop.gremlin.process.computer.Computer;
import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.Operator;
import org.apache.tinkerpop.gremlin.process.traversal.P;
@@ -188,8 +187,6 @@ public class PythonTranslator implements Translator.ScriptTranslator {
return convertStatic(((Enum) object).getDeclaringClass().getSimpleName() + ".") + SymbolHelper.toPython(object.toString());
else if (object instanceof P)
return convertPToString((P) object, new StringBuilder()).toString();
- else if (object instanceof Computer)
- return convertToString(ConfigurationConverter.getMap(((Computer) object).getConf()));
else if (object instanceof Element)
return convertToString(((Element) object).id()); // hack
else if (object instanceof Lambda)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
index 35b9b71..6165ed3 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
@@ -19,6 +19,7 @@ under the License.
import sys
from .traversal import Traversal
from .traversal import TraversalStrategies
+from .strategies import VertexProgramStrategy
from .traversal import Bytecode
from ..driver.remote_connection import RemoteStrategy
from .. import statics
@@ -37,10 +38,6 @@ class GraphTraversalSource(object):
source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
source.bytecode.add_source("withBulk", *args)
return source
- def withComputer(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("withComputer", *args)
- return source
def withPath(self, *args):
source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
source.bytecode.add_source("withPath", *args)
@@ -67,6 +64,8 @@ class GraphTraversalSource(object):
return source
def withBindings(self, bindings):
return self
+ def withComputer(self,graph_computer=None, workers=None, result=None, persist=None, vertices=None, edges=None, configuration=None):
+ return self.withStrategies(VertexProgramStrategy(graph_computer,workers,result,persist,vertices,edges,configuration))
def E(self, *args):
traversal = GraphTraversal(self.graph, self.traversal_strategies, Bytecode(self.bytecode))
traversal.bytecode.add_step("E", *args)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-python/src/main/jython/gremlin_python/process/strategies.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/strategies.py b/gremlin-python/src/main/jython/gremlin_python/process/strategies.py
index db9e094..437b4c0 100644
--- a/gremlin-python/src/main/jython/gremlin_python/process/strategies.py
+++ b/gremlin-python/src/main/jython/gremlin_python/process/strategies.py
@@ -36,30 +36,52 @@ class ElementIdStrategy(TraversalStrategy):
TraversalStrategy.__init__(self)
+# EventStrategy doesn't make sense outside JVM traversal machine
+
class HaltedTraverserStrategy(TraversalStrategy):
- def __init__(self, haltedTraverserFactory="detached"):
- TraversalStrategy.__init__(self, configuration={"haltedTraverserFactory": haltedTraverserFactory})
+ def __init__(self, halted_traverser_factory):
+ TraversalStrategy.__init__(self, configuration={"haltedTraverserFactory": halted_traverser_factory})
class PartitionStrategy(TraversalStrategy):
- def __init__(self, partitionKey, writePartition=None, readPartitions=None, includeMetaProperties=False):
- TraversalStrategy.__init__(self, configuration={"partitionKey": partitionKey,
- "includeMetaProperties": includeMetaProperties})
- if writePartition is not None:
- self.configuration["writePartition"] = writePartition
- if writePartition is not None:
- self.configuration["readPartitions"] = readPartitions
+ def __init__(self, partition_key, write_partition=None, read_partitions=None, include_meta_properties=False):
+ TraversalStrategy.__init__(self, configuration={"partitionKey": partition_key,
+ "includeMetaProperties": include_meta_properties})
+ if write_partition is not None:
+ self.configuration["writePartition"] = write_partition
+ if write_partition is not None:
+ self.configuration["readPartitions"] = read_partitions
class SubgraphStrategy(TraversalStrategy):
- def __init__(self, vertices=None, edges=None, vertexProperties=None):
+ def __init__(self, vertices=None, edges=None, vertex_properties=None):
TraversalStrategy.__init__(self)
if vertices is not None:
self.configuration["vertices"] = vertices
if edges is not None:
self.configuration["edges"] = edges
- if vertexProperties is not None:
- self.configuration["vertexProperties"] = vertexProperties
+ if vertex_properties is not None:
+ self.configuration["vertexProperties"] = vertex_properties
+
+
+class VertexProgramStrategy(TraversalStrategy):
+ def __init__(self, graph_computer=None, workers=None, persist=None, result=None, vertices=None, edges=None,
+ configuration=None):
+ TraversalStrategy.__init__(self)
+ if graph_computer is not None:
+ self.configuration["graphComputer"] = graph_computer
+ if workers is not None:
+ self.configuration["workers"] = workers
+ if persist is not None:
+ self.configuration["persist"] = persist
+ if result is not None:
+ self.configuration["result"] = result
+ if vertices is not None:
+ self.configuration["vertices"] = vertices
+ if edges is not None:
+ self.configuration["edges"] = edges
+ if configuration is not None:
+ self.configuration.update(configuration)
###########################
@@ -67,8 +89,10 @@ class SubgraphStrategy(TraversalStrategy):
###########################
class MatchAlgorithmStrategy(TraversalStrategy):
- def __init__(self, matchAlgorithm="count"):
- TraversalStrategy.__init__(self, configuration={"matchAlgorithm": matchAlgorithm})
+ def __init__(self, match_algorithm=None):
+ TraversalStrategy.__init__(self)
+ if match_algorithm is not None:
+ self.configuration["matchAlgorithm"] = match_algorithm
###########################
@@ -135,6 +159,11 @@ class RepeatUnrollStrategy(TraversalStrategy):
TraversalStrategy.__init__(self)
+class GraphFilterStrategy(TraversalStrategy):
+ def __init__(self):
+ TraversalStrategy.__init__(self)
+
+
###########################
# VERIFICATION STRATEGIES #
###########################
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
index 0de045a..a4561e9 100644
--- a/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
+++ b/gremlin-python/src/main/jython/tests/driver/test_driver_remote_connection.py
@@ -85,7 +85,7 @@ class TestDriverRemoteConnection(TestCase):
assert "person" == g.V().label().dedup().next()
#
g = g.withoutStrategies(SubgraphStrategy). \
- withComputer({"workers": 4, "vertices": __.has("name", "marko"), "edges": __.limit(0)})
+ withComputer(workers=4, vertices=__.has("name", "marko"), edges=__.limit(0))
assert 1 == g.V().count().next()
assert 0 == g.E().count().next()
assert "person" == g.V().label().next()
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
index 615a0e2..313f406 100644
--- a/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
+++ b/gremlin-python/src/main/jython/tests/structure/io/test_graphson.py
@@ -102,7 +102,7 @@ class TestGraphSONWriter(TestCase):
def test_strategies(self):
# we have a proxy model for now given that we don't want to have to have g:XXX all registered on the Gremlin traversal machine (yet)
- assert {"@type": "g:SubgraphStrategy"} == json.loads(GraphSONWriter.writeObject(SubgraphStrategy))
+ assert {"@type": "g:SubgraphStrategy", "@value": {}} == json.loads(GraphSONWriter.writeObject(SubgraphStrategy))
assert {"@type": "g:SubgraphStrategy", "@value": {
"vertices": {"@type": "g:Bytecode", "@value": {"step": [["has", "name", "marko"]]}}}} == json.loads(
GraphSONWriter.writeObject(SubgraphStrategy(vertices=__.has("name", "marko"))))
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6fdc59d2/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
index 131a9c3..8902b1f 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/TinkerGraphComputerProvider.java
@@ -18,9 +18,11 @@
*/
package org.apache.tinkerpop.gremlin.tinkergraph.process;
+import org.apache.commons.configuration.MapConfiguration;
import org.apache.tinkerpop.gremlin.GraphProvider;
import org.apache.tinkerpop.gremlin.process.computer.Computer;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.tinkergraph.TinkerGraphProvider;
@@ -40,12 +42,12 @@ public class TinkerGraphComputerProvider extends TinkerGraphProvider {
@Override
public GraphTraversalSource traversal(final Graph graph) {
return RANDOM.nextBoolean() ?
- graph.traversal().withComputer(new HashMap<String, Object>() {{
- put(Computer.WORKERS, RANDOM.nextInt(Runtime.getRuntime().availableProcessors()) + 1);
- put(Computer.GRAPH_COMPUTER, RANDOM.nextBoolean() ?
+ graph.traversal().withStrategies(VertexProgramStrategy.create(new MapConfiguration(new HashMap<String, Object>() {{
+ put(VertexProgramStrategy.WORKERS, RANDOM.nextInt(Runtime.getRuntime().availableProcessors()) + 1);
+ put(VertexProgramStrategy.GRAPH_COMPUTER, RANDOM.nextBoolean() ?
GraphComputer.class.getCanonicalName() :
TinkerGraphComputer.class.getCanonicalName());
- }}) :
+ }}))) :
graph.traversal(GraphTraversalSource.computer());
}
}