You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2018/10/01 20:09:44 UTC
tinkerpop git commit: TINKERPOP-2053 Added OptionsStrategy
Repository: tinkerpop
Updated Branches:
refs/heads/TINKERPOP-2053 [created] 91573d5c7
TINKERPOP-2053 Added OptionsStrategy
Included a test in TinkerGraph rather than the main test suite because the test really isn't easily asserted without a custom step that reads the OptionsStrategy.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/91573d5c
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/91573d5c
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/91573d5c
Branch: refs/heads/TINKERPOP-2053
Commit: 91573d5c7d44944186a9cd11ce880dec32caff47
Parents: 0d8cf16
Author: Stephen Mallette <sp...@genoprime.com>
Authored: Mon Oct 1 16:02:46 2018 -0400
Committer: Stephen Mallette <sp...@genoprime.com>
Committed: Mon Oct 1 16:02:46 2018 -0400
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../strategy/decoration/OptionsStrategy.java | 97 ++++++++++++++++++++
.../strategy/decoration/SubgraphStrategy.java | 1 -
.../structure/io/graphson/GraphSONModule.java | 5 +
.../decoration/OptionsStrategyTest.java | 38 ++++++++
.../decoration/OptionsStrategyTest.java | 55 +++++++++++
6 files changed, 196 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91573d5c/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index ae46ad4..6ca326f 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -25,6 +25,7 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
This release also includes changes from <<release-3-3-3, 3.3.3>>.
+* Added `OptionsStrategy` to allow traversals to take arbitrary traversal-wide configurations.
* Rewrote `ConnectiveStrategy` to support an arbitrary number of infix notations in a single traversal.
* GraphSON `MessageSerializer`s will automatically register the GremlinServerModule to a provided GraphSONMapper.
* Removed support for `-i` option in Gremlin Server which was previously deprecated.
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91573d5c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/OptionsStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/OptionsStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/OptionsStrategy.java
new file mode 100644
index 0000000..c66fa01
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/OptionsStrategy.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.MapConfiguration;
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * This strategy will not alter the traversal. It is only a holder for configuration options associated with the
+ * traversal meant to be accessed by steps or other classes that might have some interaction with it. It is
+ * essentially a way for users to provide traversal level configuration options that can be used in various ways by
+ * different graph providers.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class OptionsStrategy extends AbstractTraversalStrategy<TraversalStrategy.DecorationStrategy> implements TraversalStrategy.DecorationStrategy {
+ private final Map<String, Object> options;
+
+ private OptionsStrategy(final Builder builder) {
+ options = builder.options;
+ }
+
+ /**
+ * Gets the options on the strategy as an immutable {@code Map}.
+ */
+ public Map<String,Object> getOptions() {
+ return Collections.unmodifiableMap(options);
+ }
+
+ @Override
+ public Configuration getConfiguration() {
+ return new MapConfiguration(options);
+ }
+
+ @Override
+ public void apply(final Traversal.Admin<?, ?> traversal) {
+ // has not effect on the traversal itself - simply carries a options with it that individual steps
+ // can choose to use or not.
+ }
+
+ public static OptionsStrategy create(final Configuration configuration) {
+ final Builder builder = build();
+ configuration.getKeys().forEachRemaining(k -> builder.with(k, configuration.getProperty(k)));
+ return builder.create();
+ }
+
+ public static Builder build() {
+ return new Builder();
+ }
+
+ public static class Builder {
+
+ private final Map<String, Object> options = new HashMap<>();
+
+ /**
+ * Adds an key to the configuration with the value of {@code true}.
+ */
+ public Builder with(final String key) {
+ return with(key, true);
+ }
+
+ /**
+ * Adds an option to the configuration.
+ */
+ public Builder with(final String key, final Object value) {
+ options.put(key, value);
+ return this;
+ }
+
+ public OptionsStrategy create() {
+ return new OptionsStrategy(this);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91573d5c/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 10619c2..04bf801 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
@@ -43,7 +43,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
-import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
import org.apache.tinkerpop.gremlin.structure.Direction;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91573d5c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
index 1bccd7c..676481b 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/io/graphson/GraphSONModule.java
@@ -37,6 +37,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.Connec
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.ElementIdStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.EventStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.HaltedTraverserStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.PartitionStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.SubgraphStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.finalization.MatchAlgorithmStrategy;
@@ -172,6 +173,7 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
InlineFilterStrategy.class,
MatchPredicateStrategy.class,
OrderLimitStrategy.class,
+ OptionsStrategy.class,
PathProcessorStrategy.class,
PathRetractionStrategy.class,
CountStrategy.class,
@@ -288,6 +290,7 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
InlineFilterStrategy.class,
MatchPredicateStrategy.class,
OrderLimitStrategy.class,
+ OptionsStrategy.class,
PathProcessorStrategy.class,
PathRetractionStrategy.class,
CountStrategy.class,
@@ -386,6 +389,7 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
InlineFilterStrategy.class,
MatchPredicateStrategy.class,
OrderLimitStrategy.class,
+ OptionsStrategy.class,
PathProcessorStrategy.class,
PathRetractionStrategy.class,
CountStrategy.class,
@@ -494,6 +498,7 @@ abstract class GraphSONModule extends TinkerPopJacksonModule {
InlineFilterStrategy.class,
MatchPredicateStrategy.class,
OrderLimitStrategy.class,
+ OptionsStrategy.class,
PathProcessorStrategy.class,
PathRetractionStrategy.class,
CountStrategy.class,
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91573d5c/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/OptionsStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/OptionsStrategyTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/OptionsStrategyTest.java
new file mode 100644
index 0000000..064289a
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/decoration/OptionsStrategyTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration;
+
+import org.junit.Test;
+
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class OptionsStrategyTest {
+
+ @Test
+ public void shouldCreateOptionsStrategy() {
+ final OptionsStrategy strategy = OptionsStrategy.build().with("a", "test").with("b").create();
+ assertEquals("test", strategy.getOptions().get("a"));
+ assertThat(strategy.getOptions().get("b"), is(true));
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/91573d5c/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/decoration/OptionsStrategyTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/decoration/OptionsStrategyTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/decoration/OptionsStrategyTest.java
new file mode 100644
index 0000000..09ce128
--- /dev/null
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/process/traversal/strategy/decoration/OptionsStrategyTest.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tinkerpop.gremlin.tinkergraph.process.traversal.strategy.decoration;
+
+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.step.map.MapStep;
+import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.OptionsStrategy;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import static org.hamcrest.Matchers.contains;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class OptionsStrategyTest {
+
+ @Test
+ public void shouldAddOptionsToTraversal() {
+ final Graph graph = TinkerGraph.open();
+ final GraphTraversalSource optionedG = graph.traversal().withStrategies(OptionsStrategy.build().with("a", "test").with("b").create());
+ GraphTraversal t = optionedG.inject(1);
+ t = t.asAdmin().addStep(new MapStep<Object, Object>(t.asAdmin()) {
+ @Override
+ protected Object map(final Traverser.Admin<Object> traverser) {
+ final OptionsStrategy strategy = this.getTraversal().asAdmin().getStrategies().getStrategy(OptionsStrategy.class).get();
+ return Arrays.asList(strategy.getOptions().get("a"), strategy.getOptions().get("b"));
+ }
+ });
+ assertThat((Collection<Object>) t.next(), contains("test", true));
+ }
+}