You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by tw...@apache.org on 2016/07/07 22:16:20 UTC
[3/3] tinkerpop git commit: ready for integration test
ready for integration test
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/6ee66009
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/6ee66009
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/6ee66009
Branch: refs/heads/TINKERPOP-1254-final
Commit: 6ee660095e5808ca6d68a3bee2f17acd4b3660fd
Parents: e4e693e
Author: Ted Wilmes <tw...@gmail.com>
Authored: Thu Jul 7 17:16:05 2016 -0500
Committer: Ted Wilmes <tw...@gmail.com>
Committed: Thu Jul 7 17:16:05 2016 -0500
----------------------------------------------------------------------
.../process/traversal/step/PathProcessor.java | 4 +-
.../traversal/step/filter/DedupGlobalStep.java | 10 +--
.../step/filter/WherePredicateStep.java | 11 ---
.../step/filter/WhereTraversalStep.java | 16 ++--
.../process/traversal/step/map/MatchStep.java | 95 ++++----------------
.../traversal/step/util/ImmutablePath.java | 80 +----------------
.../traversal/step/util/ImmutablePathUtil.java | 37 --------
.../traversal/step/util/MutablePath.java | 16 ++--
.../optimization/PrunePathStrategy.java | 71 ---------------
.../traverser/LP_O_OB_P_S_SE_SL_Traverser.java | 4 +-
.../groovy/loaders/SugarLoaderTest.groovy | 20 ++---
.../structure/TinkerGraphPlayTest.java | 8 +-
12 files changed, 56 insertions(+), 316 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/PathProcessor.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/PathProcessor.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/PathProcessor.java
index 9282571..7d8a497 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/PathProcessor.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/PathProcessor.java
@@ -63,11 +63,9 @@ public interface PathProcessor {
void setKeepLabels(final Set<String> labels);
static void keepLabels(final Traverser traverser, final Set<String> labels) {
- if(labels == null) {
+ if(labels == null || labels.isEmpty()) {
return;
} else {
-// final Set<String> keepers = traverser.asAdmin().getTags();
-// keepers.addAll(labels);
traverser.asAdmin().keepLabels(labels);
}
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/DedupGlobalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/DedupGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/DedupGlobalStep.java
index ab5e687..78fd429 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/DedupGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/DedupGlobalStep.java
@@ -82,11 +82,6 @@ public final class DedupGlobalStep<S> extends FilterStep<S> implements Traversal
}
@Override
- public void setKeepLabels(Set<String> labels) {
- this.keepLabels = labels;
- }
-
- @Override
protected Traverser.Admin<S> processNextStart() {
final Traverser.Admin<S> traverser = super.processNextStart();
PathProcessor.keepLabels(traverser, keepLabels);
@@ -208,5 +203,10 @@ public final class DedupGlobalStep<S> extends FilterStep<S> implements Traversal
}
@Override
+ public void setKeepLabels(Set<String> labels) {
+ this.keepLabels = labels;
+ }
+
+ @Override
public Set<String> getKeepLabels() { return this.keepLabels; }
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WherePredicateStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WherePredicateStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WherePredicateStep.java
index 4162716..0ee7832 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WherePredicateStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WherePredicateStep.java
@@ -121,18 +121,7 @@ public final class WherePredicateStep<S> extends FilterStep<S> implements Scopin
@Override
protected Traverser.Admin<S> processNextStart() {
final Traverser.Admin<S> traverser = super.processNextStart();
- // add traverser tags in
-// Set<String> labels = new HashSet<>();
-// labels.addAll(traverser.getTags());
-// if(keepLabels != null ) labels.addAll(keepLabels);
-// if(keepLabels != null) System.out.println(labels);
-// System.out.println(traverser);
-// System.out.println("Before: " + traverser.path().labels());
-// System.out.println("Keeping: " + keepLabels);
-// System.out.println("IN: " + traverser.path().labels());
PathProcessor.keepLabels(traverser, keepLabels);
-// System.out.println("OUT: " + traverser.path().labels());
-// System.out.println("After: " + traverser.path().labels());
return traverser;
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTraversalStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTraversalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTraversalStep.java
index 5ba7004..078a370 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTraversalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/WhereTraversalStep.java
@@ -48,9 +48,6 @@ public final class WhereTraversalStep<S> extends FilterStep<S> implements Traver
protected final Set<String> scopeKeys = new HashSet<>();
protected Set<String> keepLabels;
- @Override
- public Set<String> getKeepLabels() { return this.keepLabels; }
-
public WhereTraversalStep(final Traversal.Admin traversal, final Traversal<?, ?> whereTraversal) {
super(traversal);
this.whereTraversal = whereTraversal.asAdmin();
@@ -93,11 +90,6 @@ public final class WhereTraversalStep<S> extends FilterStep<S> implements Traver
}
@Override
- public void setKeepLabels(Set<String> keepLabels) {
- this.keepLabels = keepLabels;
- }
-
- @Override
protected Traverser.Admin<S> processNextStart() {
final Traverser.Admin<S> traverser = super.processNextStart();
PathProcessor.keepLabels(traverser, keepLabels);
@@ -149,6 +141,14 @@ public final class WhereTraversalStep<S> extends FilterStep<S> implements Traver
TYPICAL_LOCAL_REQUIREMENTS;
}
+ @Override
+ public void setKeepLabels(Set<String> keepLabels) {
+ this.keepLabels = keepLabels;
+ }
+
+ @Override
+ public Set<String> getKeepLabels() { return this.keepLabels; }
+
//////////////////////////////
public static class WhereStartStep<S> extends MapStep<S, Object> implements Scoping {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
index 5f262bd..bb1f551 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/map/MatchStep.java
@@ -322,14 +322,11 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
if (this.connective == ConnectiveStep.Connective.AND) {
final Traversal.Admin<Object, Object> matchTraversal = this.getMatchAlgorithm().apply(traverser);
- // drop any labels that we can
-// dropUnnecessaryLabels(traverser, matchTraversal);
traverser.getTags().add(matchTraversal.getStartStep().getId());
matchTraversal.addStart(traverser); // determine which sub-pattern the traverser should try next
} else { // OR
for (final Traversal.Admin<?, ?> matchTraversal : this.matchTraversals) {
final Traverser.Admin split = traverser.split();
-// dropUnnecessaryLabels(traverser, matchTraversal);
split.getTags().add(matchTraversal.getStartStep().getId());
matchTraversal.addStart(split);
}
@@ -338,28 +335,6 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
}
}
- private void dropUnnecessaryLabels(final Traverser.Admin<Object> traverser,
- final Traversal.Admin matchTraversal) {
- if(keepLabels == null) {
- return;
- }
- final List<Traversal.Admin> remainingTraversals = getRemainingTraversals(traverser);
- remainingTraversals.add(matchTraversal);
- HashSet<String> requiredLabels = new HashSet<>();
- remainingTraversals.stream().forEach(trav -> {
- getRequiredLabels(trav, requiredLabels);
- });
- requiredLabels.addAll(keepLabels);
- if(dedupLabels != null) {
- requiredLabels.addAll(dedupLabels);
- }
- requiredLabels.add(matchTraversal.getStartStep().getId());
-// System.out.println(requiredLabels);
-// System.out.println("Before:\t" + traverser.path().labels() + "\t" + traverser.path().objects());
- traverser.keepLabels(requiredLabels);
-// System.out.println("After:\t" + traverser.path().labels() + "\t" + traverser.path().objects());
- }
-
@Override
protected Iterator<Traverser.Admin<Map<String, E>>> computerAlgorithm() throws NoSuchElementException {
while (true) {
@@ -382,13 +357,11 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
final Traversal.Admin<Object, Object> matchTraversal = this.getMatchAlgorithm().apply(traverser); // determine which sub-pattern the traverser should try next
traverser.getTags().add(matchTraversal.getStartStep().getId());
traverser.setStepId(matchTraversal.getStartStep().getId()); // go down the traversal match sub-pattern
-// dropUnnecessaryLabels(traverser, matchTraversal);
return IteratorUtils.of(traverser);
} else { // OR
final List<Traverser.Admin<Map<String, E>>> traversers = new ArrayList<>(this.matchTraversals.size());
for (final Traversal.Admin<?, ?> matchTraversal : this.matchTraversals) {
final Traverser.Admin split = traverser.split();
-// dropUnnecessaryLabels(traverser, matchTraversal);
split.getTags().add(matchTraversal.getStartStep().getId());
split.setStepId(matchTraversal.getStartStep().getId());
traversers.add(split);
@@ -400,44 +373,28 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
}
protected List<Traversal.Admin> getRemainingTraversals(final Traverser.Admin traverser) {
-
final Set<String> tags = traverser.getTags();
final List<Traversal.Admin> remainingTraversals = new ArrayList<>();
for(final Traversal.Admin matchTraversal : matchTraversals) {
if(!tags.contains(matchTraversal.getStartStep().getId())) {
remainingTraversals.add(matchTraversal);
} else {
- // see if we're currently in it
+ // if we're currently in this traversal, include it in the list of
+ // remaining traversals
for(Object s : matchTraversal.getSteps()) {
if(((Step)s).getId().equals(traverser.getStepId())) {
remainingTraversals.add(matchTraversal);
break;
}
}
-// matchTraversal.getSteps().stream().forEach(step -> {
-//
-// if(((Step)step).getId().equals(traverser.getStepId())) {
-// found = true;
-// }
-// if(found) {
-// remainingTraversals.add(matchTraversal);
-// }
-// });
}
}
-// System.out.println("Remaining: " + remainingTraversals);
return remainingTraversals;
}
private void getRequiredLabels(Traversal.Admin trav, Set<String> requiredLabels) {
- trav.getSteps().stream().forEach(step -> {
-// if(step instanceof Scoping) {
-// requiredLabels.addAll(((Scoping) step).getScopeKeys());
-// }
- if(step instanceof PathProcessor) {
- //Set<String> keep = ((PathProcessor) step).getKeepLabels();
- //if(keep != null) requiredLabels.addAll(keep);
- } else if(step instanceof Scoping) {
+ for(final Step<?, ?> step : (List<Step<?, ?>>)trav.getSteps()) {
+ if(step instanceof Scoping) {
Set<String> keep = ((Scoping)step).getScopeKeys();
if(keep != null) requiredLabels.addAll(keep);
}
@@ -447,7 +404,7 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
children.addAll(parent.getLocalChildren());
children.stream().forEach(child -> getRequiredLabels(child, requiredLabels));
}
- });
+ }
}
@Override
@@ -467,37 +424,18 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
@Override
protected Traverser.Admin<Map<String, E>> processNextStart() throws NoSuchElementException {
final Traverser.Admin<Map<String, E>> traverser = super.processNextStart();
- // remove labels that we don't need
-// System.out.println("KEEPERS: " + keepLabels);
if(keepLabels != null) {
- // add traverser tags in
- Set<String> labels = new HashSet<>();
- // determine which tags to keep vs. drop by looking at which labels still exist in the path
- //
-
-// labels.addAll(getMatchStartLabels());
-// labels.addAll(getMatchEndLabels());
-// if (keepLabels != null) System.out.println(labels);
+ final Set<String> keepers = new HashSet<>();
List<Traversal.Admin> remainingTraversals = getRemainingTraversals(traverser);
-// System.out.println("REMAINING: " + remainingTraversals.size());
-// if(remainingTraversals.size() == 1) {
-// // also remove tags...
-// System.out.println("Before droppppping: " + traverser.path().labels());
-// traverser.dropLabels(traverser.getTags());
-// System.out.println("DROPPPPPING TAGS: " + traverser.path().labels());
-// }
-// System.out.println("none");
- for (Traversal.Admin trav : remainingTraversals) {
- getRequiredLabels(trav, labels);
- }
-// labels.addAll(traverser.getTags());
- if (keepLabels != null) labels.addAll(keepLabels);
-// System.out.println(labels);
-// System.out.println("Before: " + traverser.path().labels());
-// System.out.println("Keepers: " + labels);
- PathProcessor.keepLabels(traverser, labels);
-// System.out.println("After: " + traverser.path().labels());
-// }
+ for (Traversal.Admin trav : remainingTraversals) {
+ getRequiredLabels(trav, keepers);
+ }
+ keepers.addAll(keepLabels);
+// System.out.println("Before: " + traverser.path().labels());
+// System.out.println("Before: " + traverser.path().objects());
+ PathProcessor.keepLabels(traverser, keepers);
+// System.out.println("After: " + traverser.path().labels());
+// System.out.println("After: " + traverser.path().objects());
}
return traverser;
}
@@ -639,10 +577,9 @@ public final class MatchStep<S, E> extends ComputerAwareStep<S, Map<String, E>>
public static boolean hasExecutedTraversal(final Traverser.Admin<Object> traverser, final Traversal.Admin<Object, Object> traversal) {
final boolean hasExecuted = traverser.getTags().contains(traversal.getStartStep().getId());
if(hasExecuted) {
+ // This traverser has finished this traversal so it is safe to drop the tag label.
String traversalId = traversal.getStartStep().getId();
-// System.out.println("Tag drop: " + traverser.path().labels());
traverser.dropLabels(Collections.singleton(traversalId));
-// System.out.println(traverser.path().labels());
}
return hasExecuted;
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
index 156cd61..a9bddae 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePath.java
@@ -78,78 +78,12 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
return new ImmutablePath(this.previousPath, this.currentObject, temp);
}
-// @Override
- public Path retract3(final Set<String> retractLabels) {
- if(retractLabels == null || retractLabels.isEmpty()) {
- return this;
- }
-
- List<Set<String>> labelList = this.labels();
- boolean found = false;
- for(Set<String> labelSet : labelList) {
- if (!Collections.disjoint(labelSet, retractLabels)) {
- found = true;
- break;
- }
- }
- if(!found) {
- return this;
- }
- return this;
- }
-
- private Path retract(final Set<String> labels, final List<Path> pathTrail) {
-
- Path current = pathTrail.get(0);
- if (current instanceof TailPath) {
- // return head
- return pathTrail.get(pathTrail.size() - 1);
- } else {
- ImmutablePath immutablePath = (ImmutablePath) current;
- if(!Collections.disjoint(labels, immutablePath.currentLabels)) {
- // clone all the way back up and replace parents
- ImmutablePath parentPath = null;
- for(int i = pathTrail.size() - 1; i > 0; i--) {
- ImmutablePath clonedPath = cloneImmutablePath((ImmutablePath)pathTrail.get(i));
- if(parentPath != null) {
- parentPath.previousPath = clonedPath;
- }
- parentPath = clonedPath;
- pathTrail.set(i, clonedPath);
- }
- ImmutablePath clonedCurrent = cloneImmutablePath(immutablePath);
- clonedCurrent.currentLabels.removeAll(labels);
- if(clonedCurrent.currentLabels.isEmpty()) {
- if(pathTrail.size() > 1) {
- ((ImmutablePath) pathTrail.get(1)).previousPath = clonedCurrent.previousPath;
- } else {
- pathTrail.remove(0);
- }
- }
- pathTrail.add(clonedCurrent.previousPath);
- } else {
- pathTrail.add(((ImmutablePath) pathTrail.get(0)).previousPath);
- }
- retract(labels, pathTrail);
- }
- return null;
- }
-
@Override
public Path retract(final Set<String> labels) {
if(labels == null || labels.isEmpty()) {
return this;
}
-// System.out.println("RETRACTING: " + labels);
-//
-// labels.removeIf(val -> (val.indexOf("0") >= 0));
-//
-// System.out.println("AFTER LABELS: " + labels);
-
- ImmutablePath parent;
- ImmutablePath child;
-
// first see if the labels in the set are even present in this path
boolean found = false;
for(final Set<String> labelSet : labels()) {
@@ -160,7 +94,6 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
}
if(!found) {
- // nothing to do here...
return this;
}
@@ -175,6 +108,8 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
return clone;
}
+ ImmutablePath parent;
+ ImmutablePath child;
if(this.previousPath != null) {
parent = this;
child = (ImmutablePath)this.previousPath;
@@ -203,9 +138,7 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
while(true) {
- if(!Collections.disjoint(child.currentLabels, labels)) {
-// child.currentLabels.removeAll(labels);
- } else {
+ if(Collections.disjoint(child.currentLabels, labels)) {
parents.add(child);
if(child.previousPath instanceof TailPath) {
// nothing to see...we're done here
@@ -222,7 +155,6 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
clone.currentObject = null;
}
-
// walk back up and build parent clones or reuse
// other previously cloned paths
boolean headFound = false;
@@ -243,22 +175,16 @@ public class ImmutablePath implements Path, ImmutablePathImpl, Serializable, Clo
prevPath = clonedPrev;
}
-// if(previous == null) {
if(clone.currentLabels.isEmpty()) {
lastPath.previousPath = clone.previousPath;
} else {
lastPath.previousPath = clone;
}
- // hack!
-// break;
-// }
parents = new ArrayList<>();
- headFound = true;
parents.add(lastPath);
if(child.previousPath instanceof TailPath) {
- // nothing to see...we're done here
break;
}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePathUtil.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePathUtil.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePathUtil.java
deleted file mode 100644
index 4b7259b..0000000
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/ImmutablePathUtil.java
+++ /dev/null
@@ -1,37 +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.util;
-
-import org.apache.tinkerpop.gremlin.process.traversal.Pop;
-
-import java.util.Set;
-
-/**
- * Created by twilmes on 4/11/16.
- */
-public class ImmutablePathUtil {
-
- public static ImmutablePath retract(final ImmutablePath path, final Set<String> labels) {
- // walk back through immutable path. Drop labels that are our list
- for(final String label : labels) {
- path.get(Pop.first, label);
- }
- return null;
- }
-}
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
index ba1a6ca..475f69c 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/MutablePath.java
@@ -24,13 +24,10 @@ import org.apache.tinkerpop.gremlin.process.traversal.Pop;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
-import java.util.stream.Collectors;
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -91,17 +88,16 @@ public class MutablePath implements Path, Serializable {
@Override
public Path retract(final Set<String> removeLabels) {
-
-// removeLabels.removeIf(val -> (val.indexOf("0") >= 0));
-
-// System.out.println("Removing: " + removeLabels);
-
for (int i = this.labels.size() - 1; i >= 0; i--) {
for (final String label : removeLabels) {
synchronized (this.labels.get(i)) {
- if (this.labels().get(i).contains(label)) {
+ if(this.labels.get(i).isEmpty()) {
+ this.labels.remove(i);
+ this.objects.remove(i);
+ continue;
+ }
+ if (this.labels.get(i).contains(label)) {
this.labels.get(i).remove(label);
-// System.out.println("REMOVED: " + label);
boolean empty = false;
if (this.labels.get(i).size() == 0) {
this.labels.remove(i);
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategy.java
index 5581463..5e80480 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/PrunePathStrategy.java
@@ -18,18 +18,15 @@
*/
package org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization;
-import org.apache.tinkerpop.gremlin.process.traversal.Parameterizing;
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.PathProcessor;
-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.map.MatchStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.PathStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SubgraphStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.util.Parameters;
import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
import org.apache.tinkerpop.gremlin.process.traversal.util.PathUtil;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
@@ -64,7 +61,6 @@ public final class PrunePathStrategy extends AbstractTraversalStrategy<Traversal
for(int i = steps.size() - 1; i >= 0; i--) {
final Step step = steps.get(i);
if (step instanceof PathProcessor) {
-// System.out.println("Keeping: " + keepLabels);
if(keepLabels == null) {
((PathProcessor) step).setKeepLabels(null);
} else {
@@ -105,30 +101,6 @@ public final class PrunePathStrategy extends AbstractTraversalStrategy<Traversal
}
}
-// @Override
- public void apply3(final Traversal.Admin<?, ?> traversal) {
- boolean hasPathStep = false;
- final List<PathStep> pathSteps = TraversalHelper.getStepsOfAssignableClassRecursively(PathStep.class, traversal);
- final List<SubgraphStep> subgraphSteps = TraversalHelper.getStepsOfAssignableClassRecursively(SubgraphStep.class, traversal);
- if(!pathSteps.isEmpty() || !subgraphSteps.isEmpty()) {
- hasPathStep = true;
- }
-
- // This is a bit weird at this point because the strategy application already happens in a recursive fashion
- // but we shortcut that for this strategy because we want to be able to collect all of the referenced labels
- // at all levels of the traversal and then set the keep labels accordingly for each PathProcessor
- if(!(traversal.getParent() instanceof EmptyStep)) {
- return;
- }
-
- Set<String> keepLabels = null;
- if(!hasPathStep) {
- keepLabels = new HashSet<>();
- }
-
- setKeepLabels(traversal, keepLabels);
- }
-
protected Set<String> getParentReferencedLabels(final Traversal.Admin<?, ?> traversal) {
if(traversal.getParent().equals(EmptyStep.instance())) {
return Collections.EMPTY_SET;
@@ -151,21 +123,18 @@ public final class PrunePathStrategy extends AbstractTraversalStrategy<Traversal
}
do {
Set<String> labels = PathUtil.getReferencedLabels(step);
-// System.out.println("Adding referenced labels." + labels);
if(topLevelParent) {
topLevelLabels.addAll(labels);
} else {
referencedLabels.addAll(labels);
}
step = step.getNextStep();
-// System.out.println(step);
} while(!(step.equals(EmptyStep.instance())));
if(topLevelParent) {
step = parent;
do {
if(step instanceof PathProcessor) {
((PathProcessor) step).getKeepLabels().addAll(referencedLabels);
-// System.out.println("Added keep labels to: " + step);
}
step = step.getPreviousStep();
} while (!(step.equals(EmptyStep.instance())));
@@ -225,47 +194,7 @@ public final class PrunePathStrategy extends AbstractTraversalStrategy<Traversal
}
}
-// if (currentStep instanceof Parameterizing) {
-// Parameters parameters = ((Parameterizing) currentStep).getParameters();
-// for (Traversal.Admin trav : parameters.getTraversals()) {
-// for (Object ss : trav.getSteps()) {
-// if (ss instanceof Scoping) {
-// Set<String> labels = ((Scoping) ss).getScopeKeys();
-// for (String label : labels) {
-// if (foundLabels.contains(label)) {
-// keepLabels.add(label);
-// } else {
-// // it'll get added later, b/c we can drop after this step
-// foundLabels.add(label);
-// }
-// }
-// }
-// }
-// }
-// }
-//
-// if (currentStep instanceof Scoping) {
-// Set<String> labels = new HashSet<>(((Scoping) currentStep).getScopeKeys());
-// if (currentStep instanceof MatchStep) {
-// // if this is the last step, keep everything, else just add founds
-// if (currentStep.getNextStep() instanceof EmptyStep) {
-// labels.addAll(((MatchStep) currentStep).getMatchEndLabels());
-// labels.addAll(((MatchStep) currentStep).getMatchStartLabels());
-// }
-// }
-// for (final String label : labels) {
-// if (foundLabels.contains(label)) {
-// keepLabels.add(label);
-// } else {
-// foundLabels.add(label);
-// }
-// }
-// }
if (currentStep instanceof PathProcessor) {
-// if (i != traversal.getSteps().size()) {
-// // add in all match labels
-// ((PathProcessor) currentStep).setKeepLabels(new HashSet<>(foundLabels));
-// }
((PathProcessor) currentStep).setKeepLabels(new HashSet<>(keepLabels));
}
} else {
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
index 87cfd21..2e13a33 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/traverser/LP_O_OB_P_S_SE_SL_Traverser.java
@@ -98,7 +98,9 @@ public class LP_O_OB_P_S_SE_SL_Traverser<T> extends O_OB_S_SE_SL_Traverser<T> {
@Override
public void dropLabels(final Set<String> labels) {
- this.path = path.retract(new HashSet(labels));
+ if(!labels.isEmpty()) {
+ this.path = path.retract(new HashSet(labels));
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy
index db704af..5fec65a 100644
--- a/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy
+++ b/gremlin-groovy-test/src/main/groovy/org/apache/tinkerpop/gremlin/groovy/loaders/SugarLoaderTest.groovy
@@ -93,16 +93,16 @@ class SugarLoaderTest extends AbstractGremlinTest {
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldUseTraverserCategoryCorrectly() {
-// SugarLoader.load()
-// final Traversal t = g.V.as('a').out.as('x').name.as('b').select('x').has('age').map {
-// [it.path().a, it.path().b, it.age]
-// };
-// assertTrue(t.hasNext())
-// t.forEachRemaining {
-// assertTrue(it[0] instanceof Vertex)
-// assertTrue(it[1] instanceof String)
-// assertTrue(it[2] instanceof Integer)
-// };
+ SugarLoader.load()
+ final Traversal t = g.V.as('a').out.as('x').name.as('b').select('x').has('age').map {
+ [it.path().a, it.path().b, it.age]
+ };
+ assertTrue(t.hasNext())
+ t.forEachRemaining {
+ assertTrue(it[0] instanceof Vertex)
+ assertTrue(it[1] instanceof String)
+ assertTrue(it[2] instanceof Integer)
+ };
}
@Test
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/6ee66009/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index 8cfaa55..897a837 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -326,9 +326,9 @@ public class TinkerGraphPlayTest {
c.addEdge("knows", d);
d.addEdge("knows", e);
- graph = TinkerFactory.createModern();
-// graph = TinkerGraph.open();
-// graph.io(GraphMLIo.build()).readGraph("/Users/twilmes/work/repos/incubator-tinkerpop/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/grateful-dead.xml");
+// graph = TinkerFactory.createModern();
+ graph = TinkerGraph.open();
+ graph.io(GraphMLIo.build()).readGraph("/Users/twilmes/work/repos/incubator-tinkerpop/gremlin-test/src/main/resources/org/apache/tinkerpop/gremlin/structure/io/graphml/grateful-dead.xml");
g = graph.traversal().withComputer(Computer.compute(TinkerGraphComputer.class).workers(1));
// System.out.println(
@@ -343,7 +343,7 @@ public class TinkerGraphPlayTest {
// System.out.println(g.V().as("a").out().where(neq("a")).profile().next());
- System.out.println(g.V().as("a").out().where(neq("a")).out().count().toList());
+ System.out.println(g.V().match(__.as("a").out().as("b"), __.as("b").out().as("c")).count().profile().next());
// System.out.println(g.V().choose(__.outE().count().is(0L), __.as("a"), __.as("b")).choose(__.select("a"), __.select("a"), __.select("b")).toList());