You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by da...@apache.org on 2016/10/07 15:06:52 UTC
[12/36] tinkerpop git commit: changed the new methods to
withSTrategies(Map...) and withoutStrategies(String...). Also,
added withComputer(Map). This looks a lot cleaner in Gremlin-Python. Also,
you can now register multiple strategies in one method call
changed the new methods to withSTrategies(Map...) and withoutStrategies(String...). Also, added withComputer(Map). This looks a lot cleaner in Gremlin-Python. Also, you can now register multiple strategies in one method call so you don't over-clone() and over-sort. Finally fixed a bug in JavaTranslator around Map translation. Cleaned up Partition/SubgraphStrategies -- added public static Strings for their parameters. Found a crazy bug in Jython where var arg coecing is no-bueno. Have a 'sorta fix' ... will fix it more thoroughly in another ticket. What a crazy day.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/3e4075bd
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/3e4075bd
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/3e4075bd
Branch: refs/heads/TINKERPOP-1458
Commit: 3e4075bd0997b22e3738478c4d03ab6f24b9e15f
Parents: 523ca1a
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Wed Oct 5 19:48:32 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Wed Oct 5 19:48:32 2016 -0600
----------------------------------------------------------------------
CHANGELOG.asciidoc | 6 +-
docs/src/reference/gremlin-variants.asciidoc | 8 +-
.../gremlin/jsr223/JavaTranslator.java | 42 ++++--
.../gremlin/process/computer/Computer.java | 29 ++--
.../computer/util/GraphComputerHelper.java | 25 ++++
.../gremlin/process/traversal/Bytecode.java | 9 +-
.../process/traversal/TraversalSource.java | 141 ++++++-------------
.../process/traversal/TraversalStrategy.java | 1 +
.../dsl/graph/GraphTraversalSource.java | 40 +++---
.../decoration/HaltedTraverserStrategy.java | 4 +-
.../strategy/decoration/PartitionStrategy.java | 25 ++--
.../strategy/decoration/SubgraphStrategy.java | 28 ++--
.../StandardVerificationStrategy.java | 3 +-
.../dsl/graph/GraphTraversalSourceTest.java | 19 ++-
.../groovy/jsr223/GroovyTranslatorTest.java | 37 ++++-
.../gremlin/groovy/jsr223/GroovyTranslator.java | 18 ++-
.../jsr223/GremlinJythonScriptEngine.java | 9 +-
.../gremlin/python/jsr223/PythonTranslator.java | 16 ++-
.../gremlin_python/process/graph_traversal.py | 8 --
.../driver/test_driver_remote_connection.py | 13 +-
.../python/jsr223/JythonTranslatorTest.java | 34 +++++
.../PartitionStrategyProcessTest.java | 18 +--
.../decoration/SubgraphStrategyProcessTest.java | 12 +-
.../process/TinkerGraphComputerProvider.java | 13 +-
.../decoration/HaltedTraverserStrategyTest.java | 7 +-
25 files changed, 344 insertions(+), 221 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 35ff317..f25e095 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,9 +26,11 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
TinkerPop 3.2.3 (Release Date: NOT OFFICIALLY RELEASED YET)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-* Added `TraversalSource.withComputer(Object...)` for better language variant support.
+* Fixed a `String` bug in `GroovyTranslator` and `PythonTranslator` where if the string has double-quotes, use """ """.
+* Fixed a `List` and `Map` bug in `JavaTranslator` where such collections were not being internally translated.
+* Added `TraversalSource.withComputer(Map<String,Object>)` for better language variant support.
+* Added `TraversalSource.withStrategies(Map<String,Object>)`/`withoutStrategies(String...)` for better language variant support.
* Added `PartitionStrategy.Builder.readPartitions()` and deprecated `PartitionStrategy.Builder.addPartition()`.
-* Added `TraversalSource.withStrategy(String,Object...)`/`withoutStrategy(String)` for better language variant support.
* `FilterRankStrategy` now propagates labels "right" over non-`Scoping` filters.
* Fixed a bug in `ConnectiveP` where nested equivalent connectives should be inlined.
* Fixed a bug in `IncidentToAdjacentStrategy` where `TreeStep` traversals were allowed.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/docs/src/reference/gremlin-variants.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/reference/gremlin-variants.asciidoc b/docs/src/reference/gremlin-variants.asciidoc
index 1d4099e..d74fb95 100644
--- a/docs/src/reference/gremlin-variants.asciidoc
+++ b/docs/src/reference/gremlin-variants.asciidoc
@@ -227,15 +227,15 @@ it is possible to use the `withBindings()`-model as Gremlin-Python's `Bindings.o
Traversal Strategies
~~~~~~~~~~~~~~~~~~~~
-In order to add and remove <<traversalstrategy,traversal strategies>> from a traversal source, the `withStrategy()` and
-`withoutStrategy()` steps should be used.
+In order to add and remove <<traversalstrategy,traversal strategies>> from a traversal source, the `withStrategies(Map<String,Object>...)` and
+`withoutStrategies(String...)` steps should be used.
[gremlin-python,modern]
----
-g = g.withStrategy('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy','vertices',__.hasLabel('person'),'edges',__.has('weight',gt(0.5)))
+g = g.withStrategies({'strategy':'org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy','vertices': hasLabel('person'),'edges': has('weight',gt(0.5))})
g.V().name.toList()
g.V().outE().valueMap(True).toList()
-g = g.withoutStrategy('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy')
+g = g.withoutStrategies('org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy')
g.V().name.toList()
g.V().outE().valueMap(True).toList()
----
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java
index 5d3e82d..af245c5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/jsr223/JavaTranslator.java
@@ -89,16 +89,33 @@ public final class JavaTranslator<S extends TraversalSource, T extends Traversal
////
- private Traversal.Admin<?, ?> translateFromAnonymous(final Bytecode bytecode) {
- try {
- final Traversal.Admin<?, ?> traversal = (Traversal.Admin) this.anonymousTraversal.getMethod("start").invoke(null);
- for (final Bytecode.Instruction instruction : bytecode.getStepInstructions()) {
- invokeMethod(traversal, Traversal.class, instruction.getOperator(), instruction.getArguments());
+ private Object translateObject(final Object object) {
+ if (object instanceof Bytecode.Binding)
+ return ((Bytecode.Binding) object).value();
+ else if (object instanceof Bytecode) {
+ try {
+ final Traversal.Admin<?, ?> traversal = (Traversal.Admin) this.anonymousTraversal.getMethod("start").invoke(null);
+ for (final Bytecode.Instruction instruction : ((Bytecode) object).getStepInstructions()) {
+ invokeMethod(traversal, Traversal.class, instruction.getOperator(), instruction.getArguments());
+ }
+ return traversal;
+ } catch (final Throwable e) {
+ throw new IllegalStateException(e.getMessage());
}
- return traversal;
- } catch (final Throwable e) {
- throw new IllegalStateException(e.getMessage());
- }
+ } else if (object instanceof Map) {
+ final Map<Object, Object> map = new HashMap<>(((Map) object).size());
+ for (final Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
+ map.put(translateObject(entry.getKey()), translateObject(entry.getValue()));
+ }
+ return map;
+ } else if (object instanceof List) {
+ final List<Object> list = new ArrayList<>();
+ for (final Object o : (List) object) {
+ list.add(translateObject(o));
+ }
+ return list;
+ } else
+ return object;
}
private Object invokeMethod(final Object delegate, final Class returnType, final String methodName, final Object... arguments) {
@@ -109,12 +126,7 @@ public final class JavaTranslator<S extends TraversalSource, T extends Traversal
// create a copy of the argument array so as not to mutate the original bytecode
final Object[] argumentsCopy = new Object[arguments.length];
for (int i = 0; i < arguments.length; i++) {
- if (arguments[i] instanceof Bytecode.Binding)
- argumentsCopy[i] = ((Bytecode.Binding) arguments[i]).value();
- else if (arguments[i] instanceof Bytecode)
- argumentsCopy[i] = this.translateFromAnonymous((Bytecode) arguments[i]);
- else
- argumentsCopy[i] = arguments[i];
+ argumentsCopy[i] = translateObject(arguments[i]);
}
try {
for (final Method method : methodCache.get(methodName)) {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 fdeac0b..e06a62a 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
@@ -45,27 +45,36 @@ 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;
}
+ private Computer() {
+
+ }
+
public static Computer compute(final Configuration configuration) {
try {
- final Computer computer = new Computer(configuration.containsKey("graphComputer") ?
- (Class) Class.forName(configuration.getString("graphComputer")) :
- GraphComputer.class);
+ final Computer computer = new Computer();
for (final String key : (List<String>) IteratorUtils.asList(configuration.getKeys())) {
- if (key.equals("graphComputer")) {
- // do nothing
- } else if (key.equals("workers"))
+ if (key.equals(GRAPH_COMPUTER))
+ computer.graphComputerClass = (Class) Class.forName(configuration.getString("graphComputer"));
+ else if (key.equals(WORKERS))
computer.workers = configuration.getInt(key);
- else if (key.equals("persist"))
+ else if (key.equals(PERSIST))
computer.persist = GraphComputer.Persist.valueOf(configuration.getString(key));
- else if (key.equals("result"))
+ else if (key.equals(RESULT))
computer.resultGraph = GraphComputer.ResultGraph.valueOf(configuration.getString(key));
- else if (key.equals("vertices"))
+ else if (key.equals(VERTICES))
computer.vertices = (Traversal) configuration.getProperty(key);
- else if (key.equals("edges"))
+ else if (key.equals(EDGES))
computer.edges = (Traversal) configuration.getProperty(key);
else
computer.configuration.put(key, configuration.getProperty(key));
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 468791f..5787681 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,13 +18,19 @@
*/
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;
/**
@@ -77,4 +83,23 @@ public final class GraphComputerHelper {
if (!(b instanceof MapReduce)) return false;
return a.getClass().equals(b.getClass()) && a.getMemoryKey().equals(((MapReduce) b).getMemoryKey());
}
+
+ public static TraversalStrategy[] getTraversalStrategies(final TraversalSource traversalSource, final Computer computer) {
+ 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() + 1];
+ traversalStrategies[0] = new VertexProgramStrategy(computer);
+ for (int i = 0; i < graphComputerStrategies.size(); i++) {
+ traversalStrategies[i + 1] = graphComputerStrategies.get(i);
+ }
+ return traversalStrategies;
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 3737cef..9443064 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
@@ -26,6 +26,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -249,7 +250,13 @@ public final class Bytecode implements Cloneable, Serializable {
private final Object convertArgument(final Object argument) {
if (argument instanceof Traversal)
return ((Traversal) argument).asAdmin().getBytecode();
-
+ else if (argument instanceof Map) {
+ final Map<Object, Object> map = new LinkedHashMap<>(((Map) argument).size());
+ for (final Map.Entry<?, ?> entry : ((Map<?, ?>) argument).entrySet()) {
+ map.put(convertArgument(entry.getKey()), convertArgument(entry.getValue()));
+ }
+ return map;
+ }
if (null != this.bindings) {
final String variable = this.bindings.getBoundVariable(argument);
if (null != variable)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 a31b875..5b4e663 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
@@ -24,22 +24,21 @@ 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;
import org.apache.tinkerpop.gremlin.structure.Graph;
-import org.apache.tinkerpop.gremlin.structure.util.ElementHelper;
import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
+import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BinaryOperator;
-import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
@@ -98,54 +97,56 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
public static final String withComputer = "withComputer";
public static final String withSideEffect = "withSideEffect";
public static final String withRemote = "withRemote";
- public static final String withStrategy = "withStrategy";
- public static final String withoutStrategy = "withoutStrategy";
}
/////////////////////////////
/**
- * Add a {@link TraversalStrategy} to the traversal source given the strategy name and key/value pair creation arguments.
+ * Add an arbitrary collection of {@link TraversalStrategy} instances to the traversal source.
+ * The map configurations must have a <code>strategy</code> key that is the name of the strategy class.
*
- * @param strategyName the name of the strategy (the full class name)
- * @param namedArguments key/value pair arguments where the even indices are string keys
+ * @param traversalStrategyConfigurations a collection of traversal strategies to add by configuration
* @return a new traversal source with updated strategies
*/
- public default TraversalSource withStrategy(final String strategyName, final Object... namedArguments) {
- ElementHelper.legalPropertyKeyValueArray(namedArguments);
- final Map<String, Object> configuration = new HashMap<>();
- for (int i = 0; i < namedArguments.length; i = i + 2) {
- configuration.put((String) namedArguments[i], namedArguments[i + 1]);
- }
- try {
- final TraversalStrategy<?> traversalStrategy = (TraversalStrategy) ((0 == namedArguments.length) ?
- Class.forName(strategyName).getMethod("instance").invoke(null) :
- Class.forName(strategyName).getMethod("create", Configuration.class).invoke(null, new MapConfiguration(configuration)));
- final TraversalSource clone = this.clone();
- clone.getStrategies().addStrategies(traversalStrategy);
- clone.getBytecode().addSource(Symbols.withStrategy, strategyName, namedArguments);
- return clone;
- } catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
- throw new IllegalArgumentException(e.getMessage(), e);
+ @SuppressWarnings({"unchecked"})
+ public default TraversalSource withStrategies(final Map<String, Object>... traversalStrategyConfigurations) {
+ final TraversalSource clone = this.clone();
+ final List<TraversalStrategy<?>> strategies = new ArrayList<>();
+ for (final Map<String, Object> map : traversalStrategyConfigurations) {
+ try {
+ final TraversalStrategy<?> traversalStrategy = (TraversalStrategy) ((1 == map.size()) ?
+ Class.forName((String) map.get("strategy")).getMethod("instance").invoke(null) :
+ Class.forName((String) map.get("strategy")).getMethod("create", Configuration.class).invoke(null, new MapConfiguration(map)));
+ strategies.add(traversalStrategy);
+ } catch (final ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
+ throw new IllegalArgumentException(e.getMessage(), e);
+ }
}
+ clone.getStrategies().addStrategies(strategies.toArray(new TraversalStrategy[strategies.size()]));
+ clone.getBytecode().addSource(TraversalSource.Symbols.withStrategies, traversalStrategyConfigurations);
+ return clone;
}
/**
- * Remove a {@link TraversalStrategy} from the travesal source given the strategy name.
+ * Remove an arbitrary collection of {@link TraversalStrategy} classes from the traversal source.
*
- * @param strategyName the name of the strategy (the full class name)
+ * @param traversalStrategyNames a collection of traversal strategy class names to remove
* @return a new traversal source with updated strategies
*/
- @SuppressWarnings({"unchecked", "varargs"})
- public default TraversalSource withoutStrategy(final String strategyName) {
- try {
- final TraversalSource clone = this.clone();
- clone.getStrategies().removeStrategies((Class<TraversalStrategy>) Class.forName(strategyName));
- clone.getBytecode().addSource(TraversalSource.Symbols.withoutStrategy, strategyName);
- return clone;
- } catch (final ClassNotFoundException e) {
- throw new IllegalArgumentException(e.getMessage(), e);
+ @SuppressWarnings({"unchecked"})
+ public default TraversalSource withoutStrategies(final String... traversalStrategyNames) {
+ final TraversalSource clone = this.clone();
+ final List<Class<TraversalStrategy>> strategies = new ArrayList<>();
+ for (final String name : traversalStrategyNames) {
+ try {
+ strategies.add((Class) Class.forName(name));
+ } catch (final ClassNotFoundException e) {
+ throw new IllegalArgumentException(e.getMessage(), e);
+ }
}
+ clone.getStrategies().removeStrategies(strategies.toArray(new Class[strategies.size()]));
+ clone.getBytecode().addSource(Symbols.withoutStrategies, traversalStrategyNames);
+ return clone;
}
/**
@@ -190,59 +191,28 @@ 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 namedArguments key/value pair arguments where the even indices are string keys
+ * @param computerConfiguration key/value pair map for configuring a {@link Computer}
* @return a new traversal source with updated strategies
*/
- public default TraversalSource withComputer(final Object... namedArguments) {
- if (namedArguments.length == 1) {
- if (namedArguments[0] instanceof Class)
- return this.withComputer((Class<? extends GraphComputer>) namedArguments[1]);
- else if (namedArguments[0] instanceof Computer)
- return this.withComputer((Computer) namedArguments[1]);
- }
- ElementHelper.legalPropertyKeyValueArray(namedArguments);
- final Map<String, Object> configuration = new HashMap<>();
- for (int i = 0; i < namedArguments.length; i = i + 2) {
- configuration.put((String) namedArguments[i], namedArguments[i + 1]);
- }
- final Computer computer = Computer.compute(new MapConfiguration(configuration));
- final List<TraversalStrategy<?>> graphComputerStrategies = TraversalStrategies.GlobalCache.getStrategies(computer.apply(this.getGraph()).getClass()).toList();
- final TraversalStrategy[] traversalStrategies = new TraversalStrategy[graphComputerStrategies.size() + 1];
- traversalStrategies[0] = new VertexProgramStrategy(computer);
- for (int i = 0; i < graphComputerStrategies.size(); i++) {
- traversalStrategies[i + 1] = graphComputerStrategies.get(i);
- }
- ///
+ public default TraversalSource withComputer(final Map<String, Object> computerConfiguration) {
final TraversalSource clone = this.clone();
- clone.getStrategies().addStrategies(traversalStrategies);
- clone.getBytecode().addSource(TraversalSource.Symbols.withComputer, computer);
+ clone.getStrategies().addStrategies(GraphComputerHelper.getTraversalStrategies(this, Computer.compute(new MapConfiguration(computerConfiguration))));
+ clone.getBytecode().addSource(TraversalSource.Symbols.withComputer, computerConfiguration);
return clone;
}
/**
- * Add a {@link Function} that will generate a {@link GraphComputer} from the {@link Graph} that will be used to execute the traversal.
+ * 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.
*
* @param computer a builder to generate a graph computer from the graph
* @return a new traversal source with updated strategies
*/
public default TraversalSource withComputer(final Computer computer) {
- Class<? extends GraphComputer> graphComputerClass;
- try {
- graphComputerClass = computer.apply(this.getGraph()).getClass();
- } catch (final Exception e) {
- 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);
- for (int i = 0; i < graphComputerStrategies.size(); i++) {
- traversalStrategies[i + 1] = graphComputerStrategies.get(i);
- }
- ///
final TraversalSource clone = this.clone();
- clone.getStrategies().addStrategies(traversalStrategies);
+ clone.getStrategies().addStrategies(GraphComputerHelper.getTraversalStrategies(this, computer));
clone.getBytecode().addSource(TraversalSource.Symbols.withComputer, computer);
return clone;
}
@@ -255,15 +225,8 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
* @return a new traversal source with updated strategies
*/
public default TraversalSource withComputer(final Class<? extends GraphComputer> graphComputerClass) {
- final List<TraversalStrategy<?>> graphComputerStrategies = TraversalStrategies.GlobalCache.getStrategies(graphComputerClass).toList();
- final TraversalStrategy[] traversalStrategies = new TraversalStrategy[graphComputerStrategies.size() + 1];
- traversalStrategies[0] = new VertexProgramStrategy(Computer.compute(graphComputerClass));
- for (int i = 0; i < graphComputerStrategies.size(); i++) {
- traversalStrategies[i + 1] = graphComputerStrategies.get(i);
- }
- ///
final TraversalSource clone = this.clone();
- clone.getStrategies().addStrategies(traversalStrategies);
+ clone.getStrategies().addStrategies(GraphComputerHelper.getTraversalStrategies(this, Computer.compute(graphComputerClass)));
clone.getBytecode().addSource(TraversalSource.Symbols.withComputer, graphComputerClass);
return clone;
}
@@ -275,22 +238,8 @@ public interface TraversalSource extends Cloneable, AutoCloseable {
* @return a new traversal source with updated strategies
*/
public default TraversalSource withComputer() {
- final Computer computer = Computer.compute();
- Class<? extends GraphComputer> graphComputerClass;
- try {
- graphComputerClass = computer.apply(this.getGraph()).getClass();
- } catch (final Exception e) {
- 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);
- for (int i = 0; i < graphComputerStrategies.size(); i++) {
- traversalStrategies[i + 1] = graphComputerStrategies.get(i);
- }
- ///
final TraversalSource clone = this.clone();
- clone.getStrategies().addStrategies(traversalStrategies);
+ clone.getStrategies().addStrategies(GraphComputerHelper.getTraversalStrategies(this, Computer.compute()));
clone.getBytecode().addSource(TraversalSource.Symbols.withComputer);
return clone;
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategy.java
index f01f418..a04f304 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalStrategy.java
@@ -43,6 +43,7 @@ import java.util.Set;
*/
public interface TraversalStrategy<S extends TraversalStrategy> extends Serializable, Comparable<Class<? extends TraversalStrategy>> {
+ public static final String STRATEGY = "strategy";
public void apply(final Traversal.Admin<?, ?> traversal);
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 2bd4bdf..8741894 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
@@ -45,6 +45,7 @@ import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Supplier;
@@ -122,49 +123,50 @@ public class GraphTraversalSource implements TraversalSource {
//// CONFIGURATIONS
@Override
- public GraphTraversalSource withBindings(final Bindings bindings) {
- return (GraphTraversalSource) TraversalSource.super.withBindings(bindings);
+ @SuppressWarnings({"unchecked"})
+ public GraphTraversalSource withStrategies(final Map<String, Object>... traversalStrategyConfigurations) {
+ return (GraphTraversalSource) TraversalSource.super.withStrategies(traversalStrategyConfigurations);
}
@Override
- public GraphTraversalSource withComputer(final Object... namedArguments) {
- return (GraphTraversalSource) TraversalSource.super.withComputer(namedArguments);
+ public GraphTraversalSource withoutStrategies(final String... traversalStrategyNames) {
+ return (GraphTraversalSource) TraversalSource.super.withoutStrategies(traversalStrategyNames);
}
@Override
- public GraphTraversalSource withComputer(final Computer computer) {
- return (GraphTraversalSource) TraversalSource.super.withComputer(computer);
+ public GraphTraversalSource withStrategies(final TraversalStrategy... traversalStrategies) {
+ return (GraphTraversalSource) TraversalSource.super.withStrategies(traversalStrategies);
}
@Override
- public GraphTraversalSource withComputer(final Class<? extends GraphComputer> graphComputerClass) {
- return (GraphTraversalSource) TraversalSource.super.withComputer(graphComputerClass);
+ @SuppressWarnings({"unchecked"})
+ public GraphTraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses) {
+ return (GraphTraversalSource) TraversalSource.super.withoutStrategies(traversalStrategyClasses);
}
@Override
- public GraphTraversalSource withComputer() {
- return (GraphTraversalSource) TraversalSource.super.withComputer();
+ public GraphTraversalSource withBindings(final Bindings bindings) {
+ return (GraphTraversalSource) TraversalSource.super.withBindings(bindings);
}
@Override
- public GraphTraversalSource withStrategy(final String strategyName, final Object... nameArguments) {
- return (GraphTraversalSource) TraversalSource.super.withStrategy(strategyName, nameArguments);
+ public GraphTraversalSource withComputer(final Map<String,Object> computerConfiguration) {
+ return (GraphTraversalSource) TraversalSource.super.withComputer(computerConfiguration);
}
@Override
- public GraphTraversalSource withoutStrategy(final String strategyName) {
- return (GraphTraversalSource) TraversalSource.super.withoutStrategy(strategyName);
+ public GraphTraversalSource withComputer(final Computer computer) {
+ return (GraphTraversalSource) TraversalSource.super.withComputer(computer);
}
@Override
- public GraphTraversalSource withStrategies(final TraversalStrategy... traversalStrategies) {
- return (GraphTraversalSource) TraversalSource.super.withStrategies(traversalStrategies);
+ public GraphTraversalSource withComputer(final Class<? extends GraphComputer> graphComputerClass) {
+ return (GraphTraversalSource) TraversalSource.super.withComputer(graphComputerClass);
}
@Override
- @SuppressWarnings({"unchecked", "varargs"})
- public GraphTraversalSource withoutStrategies(final Class<? extends TraversalStrategy>... traversalStrategyClasses) {
- return (GraphTraversalSource) TraversalSource.super.withoutStrategies(traversalStrategyClasses);
+ public GraphTraversalSource withComputer() {
+ return (GraphTraversalSource) TraversalSource.super.withComputer();
}
@Override
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
index cd5119b..ee1f017 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/HaltedTraverserStrategy.java
@@ -59,9 +59,11 @@ public final class HaltedTraverserStrategy extends AbstractTraversalStrategy<Tra
return traverser;
}
+ public static final String HALTED_TRAVERSER_FACTORY = "haltedTraverserFactory";
+
public static HaltedTraverserStrategy create(final Configuration configuration) {
try {
- return new HaltedTraverserStrategy(Class.forName((String) configuration.getProperty("haltedTraverserFactory")));
+ return new HaltedTraverserStrategy(Class.forName(configuration.getString(HALTED_TRAVERSER_FACTORY)));
} catch (final ClassNotFoundException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
index 1fa4105..2ee4bf3 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategy.java
@@ -324,20 +324,21 @@ public final class PartitionStrategy extends AbstractTraversalStrategy<Traversal
}
}
+ public static final String INCLUDE_META_PROPERTIES = "includeMetaProperties";
+ public static final String WRITE_PARTITION = "writePartition";
+ public static final String PARTITION_KEY = "partitionKey";
+ public static final String READ_PARTITIONS = "readPartitions";
+
public static PartitionStrategy create(final Configuration configuration) {
final PartitionStrategy.Builder builder = PartitionStrategy.build();
- configuration.getKeys().forEachRemaining(key -> {
- if (key.equals("includeMetaProperties"))
- builder.includeMetaProperties((Boolean) configuration.getProperty(key));
- else if (key.equals("writePartition"))
- builder.writePartition((String) configuration.getProperty(key));
- else if (key.equals("partitionKey"))
- builder.partitionKey((String) configuration.getProperty(key));
- else if (key.equals("readPartitions"))
- builder.readPartitions((List<String>) configuration.getProperty(key));
- else
- throw new IllegalArgumentException("The following " + PartitionStrategy.class.getSimpleName() + " configuration is unknown: " + key + ":" + configuration.getProperty(key));
- });
+ if (configuration.containsKey(INCLUDE_META_PROPERTIES))
+ builder.includeMetaProperties(configuration.getBoolean(INCLUDE_META_PROPERTIES));
+ if (configuration.containsKey(WRITE_PARTITION))
+ builder.writePartition(configuration.getString(WRITE_PARTITION));
+ if (configuration.containsKey(PARTITION_KEY))
+ builder.partitionKey(configuration.getString(PARTITION_KEY));
+ if (configuration.containsKey(READ_PARTITIONS))
+ builder.readPartitions((List) configuration.getList(READ_PARTITIONS));
return builder.create();
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
index bccff9b..d7269aa 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategy.java
@@ -90,8 +90,8 @@ public final class SubgraphStrategy extends AbstractTraversalStrategy<TraversalS
} else {
final Traversal.Admin<Edge, ?> vertexPredicate;
vertexPredicate = __.<Edge>and(
- __.inV().filter(this.vertexCriterion.clone()),
- __.outV().filter(this.vertexCriterion.clone())).asAdmin();
+ __.inV().filter(this.vertexCriterion),
+ __.outV().filter(this.vertexCriterion)).asAdmin();
// if there is a vertex predicate then there is an implied edge filter on vertices even if there is no
// edge predicate provided by the user.
@@ -204,8 +204,8 @@ public final class SubgraphStrategy extends AbstractTraversalStrategy<TraversalS
if (null != this.vertexPropertyCriterion) {
final OrStep<Object> checkPropertyCriterion = new OrStep(traversal,
new DefaultTraversal<>().addStep(new ClassFilterStep<>(traversal, VertexProperty.class, false)),
- new DefaultTraversal<>().addStep(new TraversalFilterStep<>(traversal, this.vertexPropertyCriterion.clone())));
- final Traversal.Admin nonCheckPropertyCriterion = new DefaultTraversal<>().addStep(new TraversalFilterStep<>(traversal, this.vertexPropertyCriterion.clone()));
+ new DefaultTraversal<>().addStep(new TraversalFilterStep<>(traversal, this.vertexPropertyCriterion)));
+ final Traversal.Admin nonCheckPropertyCriterion = new DefaultTraversal<>().addStep(new TraversalFilterStep<>(traversal, this.vertexPropertyCriterion));
// turn all ElementValueTraversals into filters
for (final Step<?, ?> step : traversal.getSteps()) {
@@ -291,18 +291,18 @@ public final class SubgraphStrategy extends AbstractTraversalStrategy<TraversalS
return this.vertexPropertyCriterion;
}
+ public static final String VERTICES = "vertices";
+ public static final String EDGES = "edges";
+ public static final String VERTEX_PROPERTIES = "vertexProperties";
+
public static SubgraphStrategy create(final Configuration configuration) {
final Builder builder = SubgraphStrategy.build();
- configuration.getKeys().forEachRemaining(key -> {
- if (key.equals("vertices") || key.equals("vertexCriterion"))
- builder.vertices((Traversal) configuration.getProperty(key));
- else if (key.equals("edges") || key.equals("edgeCriterion"))
- builder.edges((Traversal) configuration.getProperty(key));
- else if (key.equals("vertexProperties"))
- builder.vertexProperties((Traversal) configuration.getProperty(key));
- else
- throw new IllegalArgumentException("The following " + SubgraphStrategy.class.getSimpleName() + " configuration is unknown: " + key + ":" + configuration.getProperty(key));
- });
+ if (configuration.containsKey(VERTICES))
+ builder.vertices((Traversal) configuration.getProperty(VERTICES));
+ if (configuration.containsKey(EDGES))
+ builder.edges((Traversal) configuration.getProperty(EDGES));
+ if (configuration.containsKey(VERTEX_PROPERTIES))
+ builder.vertexProperties((Traversal) configuration.getProperty(VERTEX_PROPERTIES));
return builder.create();
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
index 917fab9..9f7f516 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
@@ -31,6 +31,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversal
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.structure.Graph;
+import java.util.ArrayList;
import java.util.Collections;
import java.util.Set;
@@ -52,7 +53,7 @@ public final class StandardVerificationStrategy extends AbstractTraversalStrateg
}
for (final Step<?, ?> step : traversal.getSteps()) {
- for (String label : step.getLabels()) {
+ for (String label : new ArrayList<>(step.getLabels())) {
if (Graph.Hidden.isHidden(label))
step.removeLabel(label);
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSourceTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSourceTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSourceTest.java
index 7604ab5..6efa4b5 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSourceTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversalSourceTest.java
@@ -24,6 +24,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.Read
import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import org.junit.Test;
+import java.util.Collections;
+import java.util.HashMap;
+
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
@@ -59,18 +62,20 @@ public class GraphTraversalSourceTest {
public void shouldSupportStringBasedStrategies() throws Exception {
GraphTraversalSource g = EmptyGraph.instance().traversal();
assertFalse(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
- g = g.withStrategy(SubgraphStrategy.class.getCanonicalName(),
- "vertices", __.hasLabel("person"),
- "vertexProperties", __.limit(0),
- "edges", __.hasLabel("knows"));
+ g = g.withStrategies(new HashMap<String, Object>() {{
+ put("strategy", SubgraphStrategy.class.getCanonicalName());
+ put("vertices", __.hasLabel("person"));
+ put("vertexProperties", __.limit(0));
+ put("edges", __.hasLabel("knows"));
+ }});
assertTrue(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
- g = g.withoutStrategy(SubgraphStrategy.class.getCanonicalName());
+ g = g.withoutStrategies(SubgraphStrategy.class.getCanonicalName());
assertFalse(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
//
assertFalse(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
- g = g.withStrategy(ReadOnlyStrategy.class.getCanonicalName());
+ g = g.withStrategies(Collections.singletonMap("strategy", ReadOnlyStrategy.class.getCanonicalName()));
assertTrue(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
- g = g.withoutStrategy(ReadOnlyStrategy.class.getCanonicalName());
+ g = g.withoutStrategies(ReadOnlyStrategy.class.getCanonicalName());
assertFalse(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
index 8060d39..df960c0 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/groovy/jsr223/GroovyTranslatorTest.java
@@ -21,16 +21,23 @@ package org.apache.tinkerpop.gremlin.groovy.jsr223;
import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
import org.apache.tinkerpop.gremlin.LoadGraphWith;
-import org.apache.tinkerpop.gremlin.groovy.jsr223.GroovyTranslator;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
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;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.util.function.Lambda;
import org.junit.Test;
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import static org.junit.Assert.assertEquals;
@@ -43,6 +50,34 @@ public class GroovyTranslatorTest extends AbstractGremlinTest {
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+ public void shouldHandleStrategies() throws Exception {
+ GraphTraversalSource g = graph.traversal();
+ g = g.withStrategies(new HashMap<String, Object>() {{
+ put(SubgraphStrategy.STRATEGY, SubgraphStrategy.class.getCanonicalName());
+ put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
+ }});
+ final Bindings bindings = new SimpleBindings();
+ bindings.put("g", g);
+ Traversal.Admin<Vertex, Object> traversal = new GremlinGroovyScriptEngine().eval(g.V().values("name").asAdmin().getBytecode(), bindings);
+ assertEquals("marko", traversal.next());
+ assertFalse(traversal.hasNext());
+ //
+ g = g.withoutStrategies(SubgraphStrategy.class.getCanonicalName());
+ traversal = new GremlinGroovyScriptEngine().eval(g.V().count().asAdmin().getBytecode(), bindings);
+ assertEquals(new Long(6), traversal.next());
+ assertFalse(traversal.hasNext());
+ //
+ g = graph.traversal().withStrategies(new HashMap<String, Object>() {{
+ put(SubgraphStrategy.STRATEGY, SubgraphStrategy.class.getCanonicalName());
+ put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
+ }}, Collections.singletonMap(ReadOnlyStrategy.STRATEGY, ReadOnlyStrategy.class.getCanonicalName()));
+ traversal = new GremlinGroovyScriptEngine().eval(g.V().values("name").asAdmin().getBytecode(), bindings);
+ assertEquals("marko", traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
+ @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldSupportStringSupplierLambdas() throws Exception {
GraphTraversalSource g = graph.traversal();
g = g.withStrategies(new TranslationStrategy(g, GroovyTranslator.of("g")));
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 aba78bb..59a07b3 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
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.P;
import org.apache.tinkerpop.gremlin.process.traversal.SackFunctions;
import org.apache.tinkerpop.gremlin.process.traversal.Translator;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
@@ -34,6 +35,7 @@ import org.apache.tinkerpop.gremlin.util.function.Lambda;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -80,7 +82,7 @@ public final class GroovyTranslator implements Translator.ScriptTranslator {
final StringBuilder traversalScript = new StringBuilder(start);
for (final Bytecode.Instruction instruction : bytecode.getInstructions()) {
final String methodName = instruction.getOperator();
- if(IS_TESTING && methodName.equals(TraversalSource.Symbols.withStrategies))
+ if (IS_TESTING && methodName.equals(TraversalSource.Symbols.withStrategies))
continue;
if (0 == instruction.getArguments().length)
traversalScript.append(".").append(methodName).append("()");
@@ -100,13 +102,23 @@ public final class GroovyTranslator implements Translator.ScriptTranslator {
if (object instanceof Bytecode.Binding)
return ((Bytecode.Binding) object).variable();
else if (object instanceof String)
- return "\"" + object + "\"";
+ return ((String) object).contains("\"") ? "\"\"\"" + object + "\"\"\"" : "\"" + object + "\"";
else if (object instanceof List) {
final List<String> list = new ArrayList<>(((List) object).size());
for (final Object item : (List) object) {
list.add(convertToString(item));
}
return list.toString();
+ } else if (object instanceof Map) {
+ final StringBuilder map = new StringBuilder("new LinkedHashMap(){{");
+ for (final Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
+ map.append("put(").
+ append(convertToString(entry.getKey())).
+ append(",").
+ append(convertToString(entry.getValue())).
+ append(");");
+ }
+ return map.append("}}").toString();
} else if (object instanceof Long)
return object + "L";
else if (object instanceof Double)
@@ -134,6 +146,8 @@ public final class GroovyTranslator implements Translator.ScriptTranslator {
return lambdaString.startsWith("{") ? lambdaString : "{" + lambdaString + "}";
} else if (object instanceof Bytecode)
return this.internalTranslate("__", (Bytecode) object);
+ else if (object instanceof Traversal)
+ return this.internalTranslate("__", ((Traversal) object).asAdmin().getBytecode());
else
return null == object ? "null" : object.toString();
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java
index 4952803..66aecf8 100644
--- a/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java
+++ b/gremlin-python/src/main/java/org/apache/tinkerpop/gremlin/python/jsr223/GremlinJythonScriptEngine.java
@@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Bytecode;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.util.CoreImports;
import org.python.jsr223.PyScriptEngine;
import org.python.jsr223.PyScriptEngineFactory;
@@ -66,8 +67,12 @@ public class GremlinJythonScriptEngine implements GremlinScriptEngine {
" elif isinstance(index,slice):\n return self.range(index.start,index.stop)\n" +
" else:\n return TypeError('Index must be int or slice')");
this.pyScriptEngine.eval(GraphTraversal.class.getSimpleName() + ".__getitem__ = getitem_bypass");
- this.pyScriptEngine.eval(GraphTraversal.class.getSimpleName() + ".__getattr__ = lambda self, key: self.values(key)");
-
+ this.pyScriptEngine.eval(GraphTraversal.class.getSimpleName() + ".__getattr__ = lambda self, key: self.values(key)\n");
+ // necessary cause of var args bug in Jython (http://bugs.jython.org/issue1615)
+ this.pyScriptEngine.eval("def withStrategies_bypass(self, *args):\n" +
+ " self.getBytecode().addSource(\"withStrategies\", *args)\n" +
+ " return self\n");
+ this.pyScriptEngine.eval(GraphTraversalSource.class.getSimpleName() + ".withStrategies = withStrategies_bypass\n");
this.pyScriptEngine.eval("\n" +
"from java.lang import Long\n" +
"import org.apache.tinkerpop.gremlin.util.function.Lambda\n" + // todo: remove or remove imported subclass names? (choose)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 4744649..65042ab 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
@@ -43,6 +43,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -102,7 +103,7 @@ public class PythonTranslator implements Translator.ScriptTranslator {
for (final Bytecode.Instruction instruction : bytecode.getInstructions()) {
final String methodName = instruction.getOperator();
final Object[] arguments = instruction.getArguments();
- if (IS_TESTING && methodName.equals(TraversalSource.Symbols.withStrategies))
+ if (IS_TESTING && methodName.equals(TraversalSource.Symbols.withStrategies) && !(instruction.getArguments()[0] instanceof Map))
continue;
else if (0 == arguments.length)
traversalScript.append(".").append(SymbolHelper.toPython(methodName)).append("()");
@@ -133,13 +134,22 @@ public class PythonTranslator implements Translator.ScriptTranslator {
if (object instanceof Bytecode.Binding)
return ((Bytecode.Binding) object).variable();
else if (object instanceof String)
- return "\"" + object + "\"";
+ return ((String) object).contains("\"") ? "\"\"\"" + object + "\"\"\"" : "\"" + object + "\"";
else if (object instanceof List) {
final List<String> list = new ArrayList<>(((List) object).size());
for (final Object item : (List) object) {
list.add(convertToString(item));
}
return list.toString();
+ } else if (object instanceof Map) {
+ final StringBuilder map = new StringBuilder("{");
+ for (final Map.Entry<?, ?> entry : ((Map<?, ?>) object).entrySet()) {
+ map.append(convertToString(entry.getKey())).
+ append(":").
+ append(convertToString(entry.getValue())).
+ append(",");
+ }
+ return map.length() > 1 ? map.substring(0, map.length() - 1) + "}" : map.append("}").toString();
} else if (object instanceof Long)
return object + "L";
else if (object instanceof Boolean)
@@ -158,6 +168,8 @@ public class PythonTranslator implements Translator.ScriptTranslator {
return convertToString(((Element) object).id()); // hack
else if (object instanceof Bytecode)
return this.internalTranslate("__", (Bytecode) object);
+ else if (object instanceof Traversal)
+ return this.internalTranslate("__", ((Traversal.Admin) object).asAdmin().getBytecode());
else if (object instanceof Computer)
return "";
else if (object instanceof Lambda)
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 46b6dee..35b9b71 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
@@ -57,18 +57,10 @@ class GraphTraversalSource(object):
source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
source.bytecode.add_source("withStrategies", *args)
return source
- def withStrategy(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("withStrategy", *args)
- return source
def withoutStrategies(self, *args):
source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
source.bytecode.add_source("withoutStrategies", *args)
return source
- def withoutStrategy(self, *args):
- source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
- source.bytecode.add_source("withoutStrategy", *args)
- return source
def withRemote(self, remote_connection):
source = GraphTraversalSource(self.graph, TraversalStrategies(self.traversal_strategies), Bytecode(self.bytecode))
source.traversal_strategies.add_strategies([RemoteStrategy(remote_connection)])
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 9914197..0524d74 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
@@ -29,6 +29,7 @@ from gremlin_python.process.traversal import Traverser
from gremlin_python.process.graph_traversal import __
from gremlin_python.structure.graph import Graph
from gremlin_python.structure.graph import Vertex
+from gremlin_python.structure.io.graphson import GraphSONWriter
class TestDriverRemoteConnection(TestCase):
@@ -63,16 +64,18 @@ class TestDriverRemoteConnection(TestCase):
def test_strategies(self):
statics.load_statics(globals())
connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
- g = Graph().traversal().withRemote(connection).withStrategy(
- "org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy",
- "vertices", __.hasLabel("person"),
- "edges", __.hasLabel("created"))
+ g = Graph().traversal().withRemote(connection).withStrategies(
+ {"strategy": "org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy",
+ "vertices": __.hasLabel("person"),
+ "edges": __.hasLabel("created")})
+ print GraphSONWriter.writeObject(g.bytecode)
assert 4 == g.V().count().next()
assert 0 == g.E().count().next()
assert 1 == g.V().label().dedup().count().next()
assert "person" == g.V().label().dedup().next()
#
- g = g.withoutStrategy("org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy").withComputer("workers", 4, "vertices", __.has("name", "marko"), "edges", __.limit(0))
+ g = g.withoutStrategies("org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy"). \
+ 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/3e4075bd/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
----------------------------------------------------------------------
diff --git a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
index 9f6dd42..40aac5c 100644
--- a/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
+++ b/gremlin-python/src/test/java/org/apache/tinkerpop/gremlin/python/jsr223/JythonTranslatorTest.java
@@ -19,16 +19,26 @@
package org.apache.tinkerpop.gremlin.python.jsr223;
+import org.apache.tinkerpop.gremlin.jsr223.GremlinScriptEngine;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
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;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.TranslationStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
+import org.apache.tinkerpop.gremlin.util.ScriptEngineCache;
import org.apache.tinkerpop.gremlin.util.function.Lambda;
import org.junit.Test;
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import static org.junit.Assert.assertEquals;
@@ -40,6 +50,30 @@ import static org.junit.Assert.assertFalse;
public class JythonTranslatorTest {
@Test
+ public void shouldHandleStrategies() throws Exception {
+ GraphTraversalSource g = TinkerFactory.createModern().traversal();
+ g = g.withStrategies(new HashMap<String, Object>() {{
+ put(SubgraphStrategy.STRATEGY, SubgraphStrategy.class.getCanonicalName());
+ put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
+ }});
+ final Bindings bindings = new SimpleBindings();
+ bindings.put("g", g);
+ //System.out.println(JythonTranslator.of("g").translate(g.V().values("name").asAdmin().getBytecode()));
+ Traversal.Admin<Vertex, String> traversal = ((GremlinScriptEngine) ScriptEngineCache.get("gremlin-jython")).eval(g.V().values("name").asAdmin().getBytecode(), bindings);
+ assertEquals("marko", traversal.next());
+ assertFalse(traversal.hasNext());
+ //
+ g = g.withStrategies(new HashMap<String, Object>() {{
+ put(SubgraphStrategy.STRATEGY, SubgraphStrategy.class.getCanonicalName());
+ put(SubgraphStrategy.VERTICES, __.has("name", "marko"));
+ }}, Collections.singletonMap(ReadOnlyStrategy.STRATEGY, ReadOnlyStrategy.class.getCanonicalName()));
+ //System.out.println(JythonTranslator.of("g").translate(g.V().values("name").asAdmin().getBytecode()));
+ traversal = ((GremlinScriptEngine) ScriptEngineCache.get("gremlin-jython")).eval(g.V().values("name").asAdmin().getBytecode(), bindings);
+ assertEquals("marko", traversal.next());
+ assertFalse(traversal.hasNext());
+ }
+
+ @Test
public void shouldSupportStringSupplierLambdas() throws Exception {
GraphTraversalSource g = TinkerFactory.createModern().traversal();
g = g.withStrategies(new TranslationStrategy(g, JythonTranslator.of("g")));
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
index 168e4fe..5d82e0e 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/PartitionStrategyProcessTest.java
@@ -31,6 +31,7 @@ import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
import org.junit.Test;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.stream.Collectors;
@@ -419,17 +420,12 @@ public class PartitionStrategyProcessTest extends AbstractGremlinProcessTest {
.partitionKey(partition).writePartition("C").readPartitions("A").create();
final GraphTraversalSource sourceCA = g.withStrategies(partitionStrategyCA);
- final PartitionStrategy partitionStrategyCABC = PartitionStrategy.build()
- .partitionKey(partition)
- .writePartition("C")
- .addReadPartition("A")
- .addReadPartition("B")
- .addReadPartition("C").create();
- final GraphTraversalSource sourceCABC = g.withStrategy(PartitionStrategy.class.getCanonicalName(),
- "writePartition", "C",
- "partitionKey", partition,
- "readPartitions", Arrays.asList("A", "B", "C"));
-
+ final GraphTraversalSource sourceCABC = g.withStrategies(new HashMap<String, Object>() {{
+ put(PartitionStrategy.STRATEGY, PartitionStrategy.class.getCanonicalName());
+ put(PartitionStrategy.WRITE_PARTITION, "C");
+ put(PartitionStrategy.PARTITION_KEY, partition);
+ put(PartitionStrategy.READ_PARTITIONS, Arrays.asList("A", "B", "C"));
+ }});
final PartitionStrategy partitionStrategyCC = PartitionStrategy.build()
.partitionKey(partition).writePartition("C").addReadPartition("C").create();
final GraphTraversalSource sourceCC = g.withStrategies(partitionStrategyCC);
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java
index 2a79c3c..4d95c96 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/SubgraphStrategyProcessTest.java
@@ -36,6 +36,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
@@ -371,7 +372,10 @@ public class SubgraphStrategyProcessTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(CREW)
public void shouldFilterVertexProperties() throws Exception {
- GraphTraversalSource sg = g.withStrategy(SubgraphStrategy.class.getCanonicalName(), "vertexProperties", __.has("startTime", P.gt(2005)));
+ GraphTraversalSource sg = g.withStrategies(new HashMap<String, Object>() {{
+ put(SubgraphStrategy.STRATEGY, SubgraphStrategy.class.getCanonicalName());
+ put(SubgraphStrategy.VERTEX_PROPERTIES, __.has("startTime", P.gt(2005)));
+ }});
checkResults(Arrays.asList("purcellville", "baltimore", "oakland", "seattle", "aachen"), sg.V().properties("location").value());
checkResults(Arrays.asList("purcellville", "baltimore", "oakland", "seattle", "aachen"), sg.V().values("location"));
if (sg.getStrategies().getStrategy(InlineFilterStrategy.class).isPresent())
@@ -397,7 +401,11 @@ public class SubgraphStrategyProcessTest extends AbstractGremlinProcessTest {
sg = g.withStrategies(SubgraphStrategy.build().vertices(has("location")).vertexProperties(hasNot("endTime")).create());
checkOrderedResults(Arrays.asList("aachen", "purcellville", "santa fe", "seattle"), sg.V().order().by("location", Order.incr).values("location"));
//
- sg = g.withStrategy(SubgraphStrategy.class.getCanonicalName(), "vertices", __.has("location"), "vertexProperties", __.hasNot("endTime"));
+ sg = g.withStrategies(new HashMap<String, Object>() {{
+ put(SubgraphStrategy.STRATEGY, SubgraphStrategy.class.getCanonicalName());
+ put(SubgraphStrategy.VERTICES, __.has("location"));
+ put(SubgraphStrategy.VERTEX_PROPERTIES, __.hasNot("endTime"));
+ }});
checkResults(Arrays.asList("aachen", "purcellville", "santa fe", "seattle"), sg.V().valueMap("location").select(Column.values).unfold().unfold());
checkResults(Arrays.asList("aachen", "purcellville", "santa fe", "seattle"), sg.V().propertyMap("location").select(Column.values).unfold().unfold().value());
//
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/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 139384f..131a9c3 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
@@ -19,12 +19,14 @@
package org.apache.tinkerpop.gremlin.tinkergraph.process;
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.traversal.dsl.graph.GraphTraversalSource;
import org.apache.tinkerpop.gremlin.structure.Graph;
import org.apache.tinkerpop.gremlin.tinkergraph.TinkerGraphProvider;
import org.apache.tinkerpop.gremlin.tinkergraph.process.computer.TinkerGraphComputer;
+import java.util.HashMap;
import java.util.Random;
/**
@@ -38,11 +40,12 @@ public class TinkerGraphComputerProvider extends TinkerGraphProvider {
@Override
public GraphTraversalSource traversal(final Graph graph) {
return RANDOM.nextBoolean() ?
- graph.traversal().withComputer(
- "workers", RANDOM.nextInt(Runtime.getRuntime().availableProcessors()) + 1,
- "graphComputer", RANDOM.nextBoolean() ?
- GraphComputer.class.getCanonicalName() :
- TinkerGraphComputer.class.getCanonicalName()) :
+ graph.traversal().withComputer(new HashMap<String, Object>() {{
+ put(Computer.WORKERS, RANDOM.nextInt(Runtime.getRuntime().availableProcessors()) + 1);
+ put(Computer.GRAPH_COMPUTER, RANDOM.nextBoolean() ?
+ GraphComputer.class.getCanonicalName() :
+ TinkerGraphComputer.class.getCanonicalName());
+ }}) :
graph.traversal(GraphTraversalSource.computer());
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3e4075bd/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/decoration/HaltedTraverserStrategyTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/decoration/HaltedTraverserStrategyTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/decoration/HaltedTraverserStrategyTest.java
index fd3dfaa..c70a31e 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/decoration/HaltedTraverserStrategyTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/decoration/HaltedTraverserStrategyTest.java
@@ -38,6 +38,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import java.util.HashMap;
+
import static org.junit.Assert.assertEquals;
/**
@@ -59,7 +61,10 @@ public class HaltedTraverserStrategyTest {
@Test
public void shouldReturnDetachedElements() {
final Graph graph = TinkerFactory.createModern();
- final GraphTraversalSource g = graph.traversal().withComputer().withStrategy(HaltedTraverserStrategy.class.getCanonicalName(), "haltedTraverserFactory", DetachedFactory.class.getCanonicalName());
+ final GraphTraversalSource g = graph.traversal().withComputer().withStrategies(new HashMap<String, Object>() {{
+ put(HaltedTraverserStrategy.STRATEGY, HaltedTraverserStrategy.class.getCanonicalName());
+ put(HaltedTraverserStrategy.HALTED_TRAVERSER_FACTORY, DetachedFactory.class.getCanonicalName());
+ }});
g.V().out().forEachRemaining(vertex -> assertEquals(DetachedVertex.class, vertex.getClass()));
g.V().out().properties("name").forEachRemaining(vertexProperty -> assertEquals(DetachedVertexProperty.class, vertexProperty.getClass()));
g.V().out().values("name").forEachRemaining(value -> assertEquals(String.class, value.getClass()));