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/04 14:37:17 UTC
tinkerpop git commit: first push. We now have
TraversalSource.withStrategy(String,
Object...) and TraversalSource.withoutStrategy(String). Added a test case to
Gremlin-Python that uses SubgraphStrategy and it works :).
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-1455 [created] e6e59e417
first push. We now have TraversalSource.withStrategy(String, Object...) and TraversalSource.withoutStrategy(String). Added a test case to Gremlin-Python that uses SubgraphStrategy and it works :).
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/e6e59e41
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/e6e59e41
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/e6e59e41
Branch: refs/heads/TINKERPOP-1455
Commit: e6e59e417f119c1b71a43141fce04cb212bc0a58
Parents: 8ab682f
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Oct 4 08:37:07 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Oct 4 08:37:07 2016 -0600
----------------------------------------------------------------------
.../process/traversal/TraversalSource.java | 52 +++++++++++++++++++-
.../dsl/graph/GraphTraversalSource.java | 10 ++++
.../strategy/decoration/SubgraphStrategy.java | 18 ++++++-
.../dsl/graph/GraphTraversalSourceTest.java | 23 +++++++++
.../gremlin/groovy/jsr223/GroovyTranslator.java | 8 +--
.../gremlin/python/jsr223/PythonTranslator.java | 3 +-
.../gremlin_python/process/graph_traversal.py | 8 +++
.../driver/test_driver_remote_connection.py | 16 +++++-
.../decoration/SubgraphStrategyProcessTest.java | 40 ++++++---------
9 files changed, 144 insertions(+), 34 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e59e41/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 0d690e9..8d5cf93 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/TraversalSource.java
@@ -19,20 +19,24 @@
package org.apache.tinkerpop.gremlin.process.traversal;
import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.MapConfiguration;
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.tinkerpop.gremlin.process.computer.Computer;
import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.decoration.VertexProgramStrategy;
import org.apache.tinkerpop.gremlin.process.remote.RemoteConnection;
-import org.apache.tinkerpop.gremlin.process.remote.traversal.strategy.decoration.RemoteStrategy;
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.List;
+import java.util.Map;
import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Function;
@@ -94,11 +98,57 @@ 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.
+ *
+ * @param strategyName the name of the strategy (the full class name)
+ * @param namedArguments key/value pair arguments where the even indices are string keys
+ * @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);
+ }
+ }
+
+ /**
+ * Remove a {@link TraversalStrategy} from the travesal source given the strategy name.
+ *
+ * @param strategyName the name of the strategy (the full class name)
+ * @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);
+ }
+ }
+
+ /**
* Add an arbitrary collection of {@link TraversalStrategy} instances to the traversal source.
*
* @param traversalStrategies a colleciton of traversal strategies to add
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e59e41/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 0525f8d..bf2da7e 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
@@ -142,6 +142,16 @@ public class GraphTraversalSource implements TraversalSource {
}
@Override
+ public GraphTraversalSource withStrategy(final String strategyName, final Object... nameArguments) {
+ return (GraphTraversalSource) TraversalSource.super.withStrategy(strategyName, nameArguments);
+ }
+
+ @Override
+ public GraphTraversalSource withoutStrategy(final String strategyName) {
+ return (GraphTraversalSource) TraversalSource.super.withoutStrategy(strategyName);
+ }
+
+ @Override
public GraphTraversalSource withStrategies(final TraversalStrategy... traversalStrategies) {
return (GraphTraversalSource) TraversalSource.super.withStrategies(traversalStrategies);
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e59e41/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 0187969..097299f 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
@@ -18,6 +18,7 @@
*/
package org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration;
+import org.apache.commons.configuration.Configuration;
import org.apache.tinkerpop.gremlin.process.traversal.Step;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
@@ -120,7 +121,7 @@ public final class SubgraphStrategy extends AbstractTraversalStrategy<TraversalS
}
private static void applyCriterion(final List<Step> stepsToApplyCriterionAfter, final Traversal.Admin traversal,
- final Traversal.Admin<? extends Element, ?> criterion) {
+ final Traversal.Admin<? extends Element, ?> criterion) {
for (final Step<?, ?> step : stepsToApplyCriterionAfter) {
// re-assign the step label to the criterion because the label should apply seamlessly after the filter
final Step filter = new TraversalFilterStep<>(traversal, criterion.clone());
@@ -290,6 +291,21 @@ public final class SubgraphStrategy extends AbstractTraversalStrategy<TraversalS
return this.vertexPropertyCriterion;
}
+ 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 configuration is unknown: " + key + ":" + configuration.getProperty(key));
+ });
+ return builder.create();
+ }
+
public static Builder build() {
return new Builder();
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e59e41/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 f9cf1df..7604ab5 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
@@ -19,9 +19,13 @@
package org.apache.tinkerpop.gremlin.process.traversal.dsl.graph;
import org.apache.tinkerpop.gremlin.process.remote.RemoteConnection;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.ReadOnlyStrategy;
import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
import org.junit.Test;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -50,4 +54,23 @@ public class GraphTraversalSourceTest {
verify(mock1, times(1)).close();
verify(mock2, times(1)).close();
}
+
+ @Test
+ 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"));
+ assertTrue(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
+ g = g.withoutStrategy(SubgraphStrategy.class.getCanonicalName());
+ assertFalse(g.getStrategies().getStrategy(SubgraphStrategy.class).isPresent());
+ //
+ assertFalse(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
+ g = g.withStrategy(ReadOnlyStrategy.class.getCanonicalName());
+ assertTrue(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
+ g = g.withoutStrategy(ReadOnlyStrategy.class.getCanonicalName());
+ assertFalse(g.getStrategies().getStrategy(ReadOnlyStrategy.class).isPresent());
+ }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e59e41/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 4b93881..88ca626 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,7 +24,6 @@ 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.TraversalSource;
import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
import org.apache.tinkerpop.gremlin.structure.Element;
@@ -78,15 +77,12 @@ 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 (methodName.equals(TraversalSource.Symbols.withStrategies))
- continue;
- final Object[] arguments = instruction.getArguments();
- if (0 == arguments.length)
+ if (0 == instruction.getArguments().length)
traversalScript.append(".").append(methodName).append("()");
else {
traversalScript.append(".");
String temp = methodName + "(";
- for (final Object object : arguments) {
+ for (final Object object : instruction.getArguments()) {
temp = temp + convertToString(object) + ",";
}
traversalScript.append(temp.substring(0, temp.length() - 1)).append(")");
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e59e41/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 90d29e8..1a84e26 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
@@ -60,6 +60,7 @@ public class PythonTranslator implements Translator.ScriptTranslator {
private final String traversalSource;
private final boolean importStatics;
+ private static final boolean isTesting = Boolean.valueOf(System.getProperty("is.testing", "false"));
PythonTranslator(final String traversalSource, final boolean importStatics) {
this.traversalSource = traversalSource;
@@ -101,7 +102,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 (methodName.equals(TraversalSource.Symbols.withStrategies))
+ if (isTesting && methodName.equals(TraversalSource.Symbols.withStrategies))
continue;
else if (0 == arguments.length)
traversalScript.append(".").append(SymbolHelper.toPython(methodName)).append("()");
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e59e41/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
----------------------------------------------------------------------
diff --git a/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py b/gremlin-python/src/main/jython/gremlin_python/process/graph_traversal.py
index 35b9b71..46b6dee 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,10 +57,18 @@ 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/e6e59e41/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 b0efcf1..f0ca27f 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
@@ -26,6 +26,7 @@ from gremlin_python import statics
from gremlin_python.statics import long
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection
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
@@ -59,6 +60,19 @@ class TestDriverRemoteConnection(TestCase):
g.V().out().profile().next()
connection.close()
+ 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"))
+ 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()
+ connection.close()
+
def test_side_effects(self):
statics.load_statics(globals())
connection = DriverRemoteConnection('ws://localhost:8182/gremlin', 'g')
@@ -104,7 +118,7 @@ class TestDriverRemoteConnection(TestCase):
assert 3 == n["lop"]
assert 1 == n["ripple"]
#
- t = g.withSideEffect('m',32).V().map(lambda: "x: x.sideEffects('m')")
+ t = g.withSideEffect('m', 32).V().map(lambda: "x: x.sideEffects('m')")
results = t.toSet()
assert 1 == len(results)
assert 32 == list(results)[0]
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e59e41/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 1a854bd..2a79c3c 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
@@ -31,7 +31,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization.Inli
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.structure.Column;
import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.T;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -66,8 +65,7 @@ public class SubgraphStrategyProcessTest extends AbstractGremlinProcessTest {
public void shouldFilterVertexCriterion() throws Exception {
final Traversal<Vertex, ?> vertexCriterion = has("name", P.within("josh", "lop", "ripple"));
- final SubgraphStrategy strategy = SubgraphStrategy.build().vertexCriterion(vertexCriterion).create();
- final GraphTraversalSource sg = create(strategy);
+ final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().vertexCriterion(vertexCriterion).create());
// three vertices are included in the subgraph
assertEquals(6, g.V().count().next().longValue());
@@ -154,7 +152,7 @@ public class SubgraphStrategyProcessTest extends AbstractGremlinProcessTest {
);
final SubgraphStrategy strategy = SubgraphStrategy.build().edgeCriterion(edgeCriterion).create();
- final GraphTraversalSource sg = create(strategy);
+ final GraphTraversalSource sg = g.withStrategies(strategy);
// all vertices are here
assertEquals(6, g.V().count().next().longValue());
@@ -261,8 +259,8 @@ public class SubgraphStrategyProcessTest extends AbstractGremlinProcessTest {
has("weight", 1.0d).hasLabel("created") // 10
);
- final SubgraphStrategy strategy = SubgraphStrategy.build().edgeCriterion(edgeCriterion).vertexCriterion(vertexCriterion).create();
- final GraphTraversalSource sg = create(strategy);
+ final SubgraphStrategy strategy = SubgraphStrategy.build().edges(edgeCriterion).vertices(vertexCriterion).create();
+ final GraphTraversalSource sg = g.withStrategies(strategy);
// three vertices are included in the subgraph
assertEquals(6, g.V().count().next().longValue());
@@ -337,8 +335,7 @@ public class SubgraphStrategyProcessTest extends AbstractGremlinProcessTest {
// this will exclude "peter"
final Traversal<Vertex, ?> vertexCriterion = has("name", P.within("ripple", "josh", "marko"));
- final SubgraphStrategy strategy = SubgraphStrategy.build().vertexCriterion(vertexCriterion).create();
- final GraphTraversalSource sg = create(strategy);
+ final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().vertexCriterion(vertexCriterion).create());
assertEquals(9, g.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue());
assertEquals(2, sg.V().as("a").out().in().as("b").dedup("a", "b").count().next().intValue());
@@ -352,8 +349,7 @@ public class SubgraphStrategyProcessTest extends AbstractGremlinProcessTest {
public void shouldGetExcludedVertex() throws Exception {
final Traversal<Vertex, ?> vertexCriterion = has("name", P.within("josh", "lop", "ripple"));
- final SubgraphStrategy strategy = SubgraphStrategy.build().vertexCriterion(vertexCriterion).create();
- final GraphTraversalSource sg = create(strategy);
+ final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().vertexCriterion(vertexCriterion).create());
sg.V(convertToVertexId("marko")).next();
}
@@ -367,8 +363,7 @@ public class SubgraphStrategyProcessTest extends AbstractGremlinProcessTest {
has("weight", 1.0d).hasLabel("created") // 10
);
- final SubgraphStrategy strategy = SubgraphStrategy.build().edgeCriterion(edgeCriterion).create();
- final GraphTraversalSource sg = create(strategy);
+ final GraphTraversalSource sg = g.withStrategies(SubgraphStrategy.build().edges(edgeCriterion).create());
sg.E(sg.E(convertToEdgeId("marko", "knows", "vadas")).next()).next();
}
@@ -376,48 +371,45 @@ public class SubgraphStrategyProcessTest extends AbstractGremlinProcessTest {
@Test
@LoadGraphWith(CREW)
public void shouldFilterVertexProperties() throws Exception {
- GraphTraversalSource sg = create(SubgraphStrategy.build().vertexProperties(has("startTime", P.gt(2005))).create());
+ GraphTraversalSource sg = g.withStrategy(SubgraphStrategy.class.getCanonicalName(), "vertexProperties", __.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())
assertFalse(TraversalHelper.hasStepOfAssignableClassRecursively(TraversalFilterStep.class, sg.V().properties("location").value().iterate().asAdmin()));
// check to make sure edge properties are not analyzed
- sg = create(SubgraphStrategy.build().vertexProperties(has("startTime", P.gt(2005))).create());
+ sg = g.withStrategies(SubgraphStrategy.build().vertexProperties(has("startTime", P.gt(2005))).create());
checkResults(Arrays.asList("purcellville", "baltimore", "oakland", "seattle", "aachen"), sg.V().as("a").properties("location").as("b").select("a").outE().properties().select("b").value().dedup());
checkResults(Arrays.asList("purcellville", "baltimore", "oakland", "seattle", "aachen"), sg.V().as("a").values("location").as("b").select("a").outE().properties().select("b").dedup());
if (sg.getStrategies().getStrategy(InlineFilterStrategy.class).isPresent())
assertFalse(TraversalHelper.hasStepOfAssignableClassRecursively(TraversalFilterStep.class, sg.V().as("a").values("location").as("b").select("a").outE().properties().select("b").dedup().iterate().asAdmin()));
//
- sg = create(SubgraphStrategy.build().vertices(has("name", P.neq("stephen"))).vertexProperties(has("startTime", P.gt(2005))).create());
+ sg = g.withStrategies(SubgraphStrategy.build().vertices(has("name", P.neq("stephen"))).vertexProperties(has("startTime", P.gt(2005))).create());
checkResults(Arrays.asList("baltimore", "oakland", "seattle", "aachen"), sg.V().properties("location").value());
checkResults(Arrays.asList("baltimore", "oakland", "seattle", "aachen"), sg.V().values("location"));
//
- sg = create(SubgraphStrategy.build().vertices(has("name", P.not(P.within("stephen", "daniel")))).vertexProperties(has("startTime", P.gt(2005))).create());
+ sg = g.withStrategies(SubgraphStrategy.build().vertices(has("name", P.not(P.within("stephen", "daniel")))).vertexProperties(has("startTime", P.gt(2005))).create());
checkResults(Arrays.asList("baltimore", "oakland", "seattle"), sg.V().properties("location").value());
checkResults(Arrays.asList("baltimore", "oakland", "seattle"), sg.V().values("location"));
//
- sg = create(SubgraphStrategy.build().vertices(has("name", P.eq("matthias"))).vertexProperties(has("startTime", P.gte(2014))).create());
+ sg = g.withStrategies(SubgraphStrategy.build().vertices(has("name", P.eq("matthias"))).vertexProperties(has("startTime", P.gte(2014))).create());
checkResults(makeMapList(1, "seattle", 1L), sg.V().groupCount().by("location"));
//
- sg = create(SubgraphStrategy.build().vertices(has("location")).vertexProperties(hasNot("endTime")).create());
+ 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 = create(SubgraphStrategy.build().vertices(has("location")).vertexProperties(hasNot("endTime")).create());
+ sg = g.withStrategy(SubgraphStrategy.class.getCanonicalName(), "vertices", __.has("location"), "vertexProperties", __.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());
//
- sg = create(SubgraphStrategy.build().edges(__.<Edge>hasLabel("uses").has("skill", 5)).create());
+ sg = g.withStrategies(SubgraphStrategy.build().edges(__.<Edge>hasLabel("uses").has("skill", 5)).create());
checkResults(Arrays.asList(5, 5, 5), sg.V().outE().valueMap().select(Column.values).unfold());
checkResults(Arrays.asList(5, 5, 5), sg.V().outE().propertyMap().select(Column.values).unfold().value());
//
- sg = create(SubgraphStrategy.build().vertexProperties(__.hasNot("skill")).create());
+ sg = g.withStrategies(SubgraphStrategy.build().vertexProperties(__.hasNot("skill")).create());
checkResults(Arrays.asList(3, 3, 3, 4, 4, 5, 5, 5), sg.V().outE("uses").values("skill"));
checkResults(Arrays.asList(3, 3, 3, 4, 4, 5, 5, 5), sg.V().as("a").properties().select("a").dedup().outE().values("skill"));
checkResults(Arrays.asList(3, 3, 3, 4, 4, 5, 5, 5), sg.V().as("a").properties().select("a").dedup().outE().properties("skill").as("b").identity().select("b").by(__.value()));
}
- private GraphTraversalSource create(final SubgraphStrategy strategy) {
- return graphProvider.traversal(graph, strategy);
- }
}