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:46 UTC
[7/7] tinkerpop git commit: finalized the Gremlin-Python
TraversalStrategy and Computer work. Able to expose Translators to more
tests. This is soooooooooooo much cleaner and intutive. Stoked.
finalized the Gremlin-Python TraversalStrategy and Computer work. Able to expose Translators to more tests. This is soooooooooooo much cleaner and intutive. Stoked.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/9b133834
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/9b133834
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/9b133834
Branch: refs/heads/master
Commit: 9b13383449e23dd3a8e13d3c60736823f6e03ae5
Parents: 6fdc59d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Oct 7 14:57:06 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Oct 7 14:57:06 2016 -0600
----------------------------------------------------------------------
.../gremlin/process/computer/Computer.java | 17 ++-
.../decoration/VertexProgramStrategy.java | 132 ++++++++-----------
.../computer/util/GraphComputerHelper.java | 24 ----
.../process/traversal/TraversalSource.java | 17 +--
.../gremlin/python/jsr223/PythonProvider.java | 3 -
.../TinkerGraphGraphSONTranslatorProvider.java | 2 -
6 files changed, 75 insertions(+), 120 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9b133834/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 a82b4e6..34b1fa4 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
@@ -19,17 +19,13 @@
package org.apache.tinkerpop.gremlin.process.computer;
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.MapConfiguration;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.structure.Vertex;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import java.io.Serializable;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
import java.util.function.Function;
@@ -53,6 +49,7 @@ public final class Computer implements Function<Graph, GraphComputer>, Serializa
private Computer() {
}
+
public static Computer compute() {
return new Computer(GraphComputer.class);
}
@@ -61,12 +58,24 @@ public final class Computer implements Function<Graph, GraphComputer>, Serializa
return new Computer(graphComputerClass);
}
+ public Computer graphComputer(final Class<? extends GraphComputer> graphComputerClass) {
+ final Computer clone = this.clone();
+ clone.graphComputerClass = graphComputerClass;
+ return clone;
+ }
+
public Computer configure(final String key, final Object value) {
final Computer clone = this.clone();
clone.configuration.put(key, value);
return clone;
}
+ public Computer configure(final Map<String, Object> configurations) {
+ final Computer clone = this.clone();
+ clone.configuration.putAll(configurations);
+ return clone;
+ }
+
public Computer workers(final int workers) {
final Computer clone = this.clone();
clone.workers = workers;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9b133834/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 42f9bef..21c1ae6 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
@@ -30,6 +30,7 @@ import org.apache.tinkerpop.gremlin.process.computer.traversal.step.map.Traversa
import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.decoration.RemoteStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.Step;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
@@ -54,40 +55,14 @@ 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 final Computer computer;
private VertexProgramStrategy() {
- this(null, -1, null, null, null, null, null);
-
+ this(null);
}
public VertexProgramStrategy(final 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());
- }
+ this.computer = computer;
}
public Computer getComputer() {
@@ -188,6 +163,20 @@ public final class VertexProgramStrategy extends AbstractTraversalStrategy<Trave
return optional.isPresent() ? Optional.of(((VertexProgramStrategy) optional.get()).computer) : Optional.empty();
}
+ public void addGraphComputerStrategies(final TraversalSource traversalSource) {
+ Class<? extends GraphComputer> graphComputerClass;
+ if (this.computer.getGraphComputerClass().equals(GraphComputer.class)) {
+ try {
+ graphComputerClass = this.computer.apply(traversalSource.getGraph()).getClass();
+ } catch (final Exception e) {
+ graphComputerClass = GraphComputer.class;
+ }
+ } else
+ graphComputerClass = this.computer.getGraphComputerClass();
+ final List<TraversalStrategy<?>> graphComputerStrategies = TraversalStrategies.GlobalCache.getStrategies(graphComputerClass).toList();
+ traversalSource.getStrategies().addStrategies(graphComputerStrategies.toArray(new TraversalStrategy[graphComputerStrategies.size()]));
+ }
+
////////////////////////////////////////////////////////////
public static final String GRAPH_COMPUTER = "graphComputer";
@@ -197,24 +186,42 @@ public final class VertexProgramStrategy extends AbstractTraversalStrategy<Trave
public static final String VERTICES = "vertices";
public static final String EDGES = "edges";
+ @Override
+ public Configuration getConfiguration() {
+ final Map<String, Object> map = new HashMap<>();
+ map.put(GRAPH_COMPUTER, this.computer.getGraphComputerClass().getCanonicalName());
+ if (-1 != this.computer.getWorkers())
+ map.put(WORKERS, this.computer.getWorkers());
+ if (null != this.computer.getPersist())
+ map.put(PERSIST, this.computer.getPersist().name());
+ if (null != this.computer.getResultGraph())
+ map.put(RESULT, this.computer.getResultGraph().name());
+ if (null != this.computer.getVertices())
+ map.put(VERTICES, this.computer.getVertices());
+ if (null != this.computer.getEdges())
+ map.put(EDGES, this.computer.getEdges());
+ map.putAll(this.computer.getConfiguration());
+ return new MapConfiguration(map);
+ }
+
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));
+ builder.graphComputer((Class) Class.forName(configuration.getString(key)));
else if (key.equals(WORKERS))
- builder.workers = configuration.getInt(key);
+ builder.workers(configuration.getInt(key));
else if (key.equals(PERSIST))
- builder.persist = GraphComputer.Persist.valueOf(configuration.getString(key));
+ builder.persist(GraphComputer.Persist.valueOf(configuration.getString(key)));
else if (key.equals(RESULT))
- builder.resultGraph = GraphComputer.ResultGraph.valueOf(configuration.getString(key));
+ builder.result(GraphComputer.ResultGraph.valueOf(configuration.getString(key)));
else if (key.equals(VERTICES))
- builder.vertices = (Traversal) configuration.getProperty(key);
+ builder.vertices((Traversal) configuration.getProperty(key));
else if (key.equals(EDGES))
- builder.edges = (Traversal) configuration.getProperty(key);
+ builder.edges((Traversal) configuration.getProperty(key));
else
- builder.configuration.put(key, configuration.getProperty(key));
+ builder.configure(key, configuration.getProperty(key));
}
return builder.create();
} catch (final ClassNotFoundException e) {
@@ -222,88 +229,65 @@ public final class VertexProgramStrategy extends AbstractTraversalStrategy<Trave
}
}
- @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 Computer computer = Computer.compute();
private Builder() {
}
+ public Builder computer(final Computer computer) {
+ this.computer = computer;
+ return this;
+ }
+
public Builder graphComputer(final Class<? extends GraphComputer> graphComputerClass) {
- this.graphComputerClass = graphComputerClass;
+ this.computer = this.computer.graphComputer(graphComputerClass);
return this;
}
public Builder configure(final String key, final Object value) {
- this.configuration.put(key, value);
+ this.computer = this.computer.configure(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());
- }
+ this.computer = this.computer.configure(configurations);
return this;
}
public Builder workers(final int workers) {
- this.workers = workers;
+ this.computer = this.computer.workers(workers);
return this;
}
public Builder persist(final GraphComputer.Persist persist) {
- this.persist = persist;
+ this.computer = this.computer.persist(persist);
return this;
}
public Builder result(final GraphComputer.ResultGraph resultGraph) {
- this.resultGraph = resultGraph;
+ this.computer = this.computer.result(resultGraph);
return this;
}
public Builder vertices(final Traversal<Vertex, Vertex> vertices) {
- this.vertices = vertices;
+ this.computer = this.computer.vertices(vertices);
return this;
}
public Builder edges(final Traversal<Vertex, Edge> edges) {
- this.edges = edges;
+ this.computer = this.computer.edges(edges);
return this;
}
public VertexProgramStrategy create() {
- return new VertexProgramStrategy(this.graphComputerClass, this.workers, this.resultGraph, this.persist, this.vertices, this.edges, this.configuration);
+ return new VertexProgramStrategy(this.computer);
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9b133834/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 f624545..dce1934 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
@@ -18,19 +18,13 @@
*/
package org.apache.tinkerpop.gremlin.process.computer.util;
-import org.apache.tinkerpop.gremlin.process.computer.Computer;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.computer.MapReduce;
import org.apache.tinkerpop.gremlin.process.computer.Memory;
import org.apache.tinkerpop.gremlin.process.computer.VertexProgram;
-import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
-import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.structure.Graph;
import java.lang.reflect.Method;
-import java.util.List;
import java.util.Optional;
/**
@@ -84,22 +78,4 @@ public final class GraphComputerHelper {
return a.getClass().equals(b.getClass()) && a.getMemoryKey().equals(((MapReduce) b).getMemoryKey());
}
- 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 {
- graphComputerClass = computer.apply(traversalSource.getGraph()).getClass();
- } catch (final Exception e) {
- graphComputerClass = GraphComputer.class;
- }
- } else
- graphComputerClass = computer.getGraphComputerClass();
- final List<TraversalStrategy<?>> graphComputerStrategies = TraversalStrategies.GlobalCache.getStrategies(graphComputerClass).toList();
- final TraversalStrategy[] traversalStrategies = new TraversalStrategy[graphComputerStrategies.size()];
- for (int i = 0; i < graphComputerStrategies.size(); i++) {
- traversalStrategies[i] = graphComputerStrategies.get(i);
- }
- return traversalStrategies;
- }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9b133834/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 0185a33..7364b50 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
@@ -23,7 +23,6 @@ import org.apache.commons.configuration.PropertiesConfiguration;
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.computer.util.GraphComputerHelper;
import org.apache.tinkerpop.gremlin.process.remote.RemoteConnection;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SackStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SideEffectStrategy;
@@ -108,8 +107,7 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
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;
+ ((VertexProgramStrategy) traversalStrategy).addGraphComputerStrategies(clone);
}
}
return clone;
@@ -150,14 +148,7 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
* @return a new traversal source with updated strategies
*/
public default TraversalSource withComputer(final Computer computer) {
- 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());
+ return this.withStrategies(new VertexProgramStrategy(computer));
}
/**
@@ -168,7 +159,7 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
* @return a new traversal source with updated strategies
*/
public default TraversalSource withComputer(final Class<? extends GraphComputer> graphComputerClass) {
- return this.withStrategies(VertexProgramStrategy.build().graphComputer(graphComputerClass).create());
+ return this.withStrategies(new VertexProgramStrategy(Computer.compute(graphComputerClass)));
}
/**
@@ -178,7 +169,7 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
* @return a new traversal source with updated strategies
*/
public default TraversalSource withComputer() {
- return this.withStrategies(VertexProgramStrategy.build().create());
+ return this.withStrategies(new VertexProgramStrategy(Computer.compute()));
}
/**
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9b133834/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java
index 34f48ef..fe04156 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/PythonProvider.java
@@ -73,9 +73,6 @@ public class PythonProvider extends AbstractGraphProvider {
"shouldHidePartitionKeyForValues",
"g_withSackXBigInteger_TEN_powX1000X_assignX_V_localXoutXknowsX_barrierXnormSackXX_inXknowsX_barrier_sack",
//
- PeerPressureTest.Traversals.class.getCanonicalName(),
- ProfileTest.Traversals.class.getCanonicalName(), // only fails in OLAP
- PageRankTest.Traversals.class.getCanonicalName(),
ProgramTest.Traversals.class.getCanonicalName(),
TraversalInterruptionTest.class.getCanonicalName(),
TraversalInterruptionComputerTest.class.getCanonicalName(),
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/9b133834/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/io/graphson/TinkerGraphGraphSONTranslatorProvider.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/io/graphson/TinkerGraphGraphSONTranslatorProvider.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/io/graphson/TinkerGraphGraphSONTranslatorProvider.java
index 97fa7fa..88a2327 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/io/graphson/TinkerGraphGraphSONTranslatorProvider.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/io/graphson/TinkerGraphGraphSONTranslatorProvider.java
@@ -54,8 +54,6 @@ public class TinkerGraphGraphSONTranslatorProvider extends TinkerGraphProvider {
"g_V_hasLabelXpersonX_asXpX_VXsoftwareX_addInEXuses_pX",
"g_VXv1X_hasXage_gt_30X",
//
-
- PageRankTest.Traversals.class.getCanonicalName(),
ProgramTest.Traversals.class.getCanonicalName(),
TraversalInterruptionTest.class.getCanonicalName(),
TraversalInterruptionComputerTest.class.getCanonicalName(),