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 2017/03/24 14:41:49 UTC
[05/19] tinkerpop git commit: removed CyclicPathStep and
SimplePathStep for a more abstract,
generalized step called PathFilterStep which handles cyclic/simple filtering
as well as to() and from() modulation. Updated UPGRADE docs. Will add
by()-modulatio
removed CyclicPathStep and SimplePathStep for a more abstract, generalized step called PathFilterStep which handles cyclic/simple filtering as well as to() and from() modulation. Updated UPGRADE docs. Will add by()-modulation to PathFilterStep next.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/65b3ad06
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/65b3ad06
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/65b3ad06
Branch: refs/heads/master
Commit: 65b3ad06b15b75ae944c11bfbdc592994fa706b2
Parents: 0fe3b1d
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Thu Mar 16 09:14:40 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Thu Mar 16 09:14:40 2017 -0600
----------------------------------------------------------------------
.../upgrade/release-3.2.x-incubating.asciidoc | 7 ++
.../traversal/dsl/graph/GraphTraversal.java | 11 ++-
.../traversal/step/filter/CyclicPathStep.java | 46 ------------
.../traversal/step/filter/PathFilterStep.java | 75 ++++++++++++++++++++
.../traversal/step/filter/SimplePathStep.java | 47 ------------
.../optimization/FilterRankingStrategy.java | 5 +-
.../IncidentToAdjacentStrategy.java | 7 +-
.../step/filter/PathFilterStepTest.java | 47 ++++++++++++
8 files changed, 139 insertions(+), 106 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65b3ad06/docs/src/upgrade/release-3.2.x-incubating.asciidoc
----------------------------------------------------------------------
diff --git a/docs/src/upgrade/release-3.2.x-incubating.asciidoc b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
index 78c276b..a770ed8 100644
--- a/docs/src/upgrade/release-3.2.x-incubating.asciidoc
+++ b/docs/src/upgrade/release-3.2.x-incubating.asciidoc
@@ -63,6 +63,13 @@ See: link:https://issues.apache.org/jira/browse/TINKERPOP-1599[TINKERPOP-1599]
Upgrading for Providers
~~~~~~~~~~~~~~~~~~~~~~~
+SimplePathStep and CyclicPathStep now PathFilterStep
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+
+The Gremlin traversal machine use to support two step instructions: `SimplePathStep` and `CyclicPathStep`. These have
+been replaced by a high-level instruction called `PathFilterStep` which is boolean configured for simple or cyclic paths.
+Furthermore, `PathFilterStep` also support `from()`-, `to()`-, and `by()`-modulation.
+
LazyBarrierStrategy No Longer End Appends Barriers
++++++++++++++++++++++++++++++++++++++++++++++++++
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65b3ad06/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
index 4344aaf..0b95479 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/dsl/graph/GraphTraversal.java
@@ -48,7 +48,6 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.branch.UnionStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.AndStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.CoinStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.ConnectiveStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.filter.CyclicPathStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.DedupGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.DropStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep;
@@ -56,9 +55,9 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.LambdaFilterStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.NotStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.OrStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.PathFilterStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.SampleGlobalStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.filter.SimplePathStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.TailGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.TimeLimitStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep;
@@ -1783,25 +1782,25 @@ public interface GraphTraversal<S, E> extends Traversal<S, E> {
/**
* Filter the <code>E</code> object if its {@link Traverser#path} is not {@link Path#isSimple}.
*
- * @return the traversal with an appended {@link SimplePathStep}.
+ * @return the traversal with an appended {@link PathFilterStep}.
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#simplepath-step" target="_blank">Reference Documentation - SimplePath Step</a>
* @since 3.0.0-incubating
*/
public default GraphTraversal<S, E> simplePath() {
this.asAdmin().getBytecode().addStep(Symbols.simplePath);
- return this.asAdmin().addStep(new SimplePathStep<>(this.asAdmin()));
+ return this.asAdmin().addStep(new PathFilterStep<E>(this.asAdmin(), true));
}
/**
* Filter the <code>E</code> object if its {@link Traverser#path} is {@link Path#isSimple}.
*
- * @return the traversal with an appended {@link CyclicPathStep}.
+ * @return the traversal with an appended {@link PathFilterStep}.
* @see <a href="http://tinkerpop.apache.org/docs/${project.version}/reference/#cyclicpath-step" target="_blank">Reference Documentation - CyclicPath Step</a>
* @since 3.0.0-incubating
*/
public default GraphTraversal<S, E> cyclicPath() {
this.asAdmin().getBytecode().addStep(Symbols.cyclicPath);
- return this.asAdmin().addStep(new CyclicPathStep<>(this.asAdmin()));
+ return this.asAdmin().addStep(new PathFilterStep<E>(this.asAdmin(), false));
}
/**
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65b3ad06/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CyclicPathStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CyclicPathStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CyclicPathStep.java
deleted file mode 100644
index e9c5dcf..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/CyclicPathStep.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.step.filter;
-
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
-import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
-
-import java.util.Collections;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class CyclicPathStep<S> extends FilterStep<S> {
-
- public CyclicPathStep(final Traversal.Admin traversal) {
- super(traversal);
- }
-
- @Override
- protected boolean filter(final Traverser.Admin<S> traverser) {
- return !traverser.path().isSimple();
- }
-
- @Override
- public Set<TraverserRequirement> getRequirements() {
- return Collections.singleton(TraverserRequirement.PATH);
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65b3ad06/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStep.java
new file mode 100644
index 0000000..bbc8168
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStep.java
@@ -0,0 +1,75 @@
+/*
+ * 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.step.filter;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
+import org.apache.tinkerpop.gremlin.process.traversal.step.FromToModulating;
+import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+
+import java.util.Collections;
+import java.util.Set;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public final class PathFilterStep<S> extends FilterStep<S> implements FromToModulating {
+
+ protected String fromLabel;
+ protected String toLabel;
+ private boolean isSimple;
+
+ public PathFilterStep(final Traversal.Admin traversal, final boolean isSimple) {
+ super(traversal);
+ this.isSimple = isSimple;
+ }
+
+ @Override
+ protected boolean filter(final Traverser.Admin<S> traverser) {
+ return traverser.path().getSubPath(this.fromLabel, this.toLabel).isSimple() == this.isSimple;
+ }
+
+ @Override
+ public Set<TraverserRequirement> getRequirements() {
+ return Collections.singleton(TraverserRequirement.PATH);
+ }
+
+ public void addFrom(final String fromLabel) {
+ this.fromLabel = fromLabel;
+ }
+
+ public void addTo(final String toLabel) {
+ this.toLabel = toLabel;
+ }
+
+ @Override
+ public String toString() {
+ return StringFactory.stepString(this, this.isSimple ? "simple" : "cyclic", this.fromLabel, this.toLabel);
+ }
+
+ @Override
+ public int hashCode() {
+ return super.hashCode() ^
+ Boolean.hashCode(this.isSimple) ^
+ (null == this.fromLabel ? "null".hashCode() : this.fromLabel.hashCode()) ^
+ (null == this.toLabel ? "null".hashCode() : this.toLabel.hashCode());
+ }
+}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65b3ad06/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/SimplePathStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/SimplePathStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/SimplePathStep.java
deleted file mode 100644
index 5789803..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/SimplePathStep.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.step.filter;
-
-
-import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
-import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
-import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
-
-import java.util.Collections;
-import java.util.Set;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public final class SimplePathStep<S> extends FilterStep<S> {
-
- public SimplePathStep(final Traversal.Admin traversal) {
- super(traversal);
- }
-
- @Override
- protected boolean filter(final Traverser.Admin<S> traverser) {
- return traverser.path().isSimple();
- }
-
- @Override
- public Set<TraverserRequirement> getRequirements() {
- return Collections.singleton(TraverserRequirement.PATH);
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65b3ad06/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategy.java
index 3649615..6ca676a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategy.java
@@ -26,14 +26,13 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.Scoping;
import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.AndStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.ClassFilterStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.filter.CyclicPathStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.DedupGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.NotStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.OrStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.filter.SimplePathStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.PathFilterStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.WherePredicateStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.WhereTraversalStep;
@@ -129,7 +128,7 @@ public final class FilterRankingStrategy extends AbstractTraversalStrategy<Trave
rank = 2;
else if (step instanceof WherePredicateStep && ((WherePredicateStep) step).getLocalChildren().isEmpty())
rank = 3;
- else if (step instanceof SimplePathStep || step instanceof CyclicPathStep)
+ else if (step instanceof PathFilterStep)
rank = 4;
else if (step instanceof TraversalFilterStep || step instanceof NotStep)
rank = 5;
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65b3ad06/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
index 4270ac3..1c96cf8 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/IncidentToAdjacentStrategy.java
@@ -23,8 +23,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Step;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.step.LambdaHolder;
-import org.apache.tinkerpop.gremlin.process.traversal.step.filter.CyclicPathStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.filter.SimplePathStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.PathFilterStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeOtherVertexStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.PathStep;
@@ -72,8 +71,8 @@ public final class IncidentToAdjacentStrategy extends AbstractTraversalStrategy<
private static final IncidentToAdjacentStrategy INSTANCE = new IncidentToAdjacentStrategy();
private static final String MARKER = Graph.Hidden.hide("gremlin.incidentToAdjacent");
- private static final Set<Class> INVALIDATING_STEP_CLASSES = new HashSet<>(Arrays.asList(CyclicPathStep.class,
- PathStep.class, SimplePathStep.class, TreeStep.class, TreeSideEffectStep.class, LambdaHolder.class));
+ private static final Set<Class> INVALIDATING_STEP_CLASSES = new HashSet<>(Arrays.asList(
+ PathStep.class, PathFilterStep.class, TreeStep.class, TreeSideEffectStep.class, LambdaHolder.class));
private IncidentToAdjacentStrategy() {
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/65b3ad06/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStepTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStepTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStepTest.java
new file mode 100644
index 0000000..ff994e8
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/PathFilterStepTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.step.filter;
+
+import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.StepTest;
+
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class PathFilterStepTest extends StepTest {
+
+ @Override
+ protected List<Traversal> getTraversals() {
+ return Arrays.asList(
+ __.simplePath(),
+ __.simplePath().from("a").to("b"),
+ __.simplePath().from("a"),
+ __.simplePath().to("b"),
+ __.cyclicPath().from("a"),
+ __.cyclicPath().to("b"),
+ __.cyclicPath().from("a").to("b"),
+ __.cyclicPath()
+ );
+ }
+}