tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ok...@apache.org
Subject tinkerpop git commit: more test cases for InlineFilterStrategy and added a constraint to make it less likely to happen for and() and filter().
Date Tue, 27 Sep 2016 16:40:11 GMT
Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1456 bf14ef708 -> bb5e71be7


more test cases for InlineFilterStrategy and added a constraint to make it less likely to
happen for and() and filter().


Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/bb5e71be
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/bb5e71be
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/bb5e71be

Branch: refs/heads/TINKERPOP-1456
Commit: bb5e71be7017f9fa2da5ce32b8c9f767e8d90acc
Parents: bf14ef7
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Tue Sep 27 10:40:03 2016 -0600
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Tue Sep 27 10:40:03 2016 -0600

----------------------------------------------------------------------
 .../optimization/InlineFilterStrategy.java      | 31 ++++++++++++++++++--
 .../process/traversal/util/TraversalHelper.java | 12 +++++++-
 .../optimization/InlineFilterStrategyTest.java  | 13 ++++++--
 3 files changed, 50 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bb5e71be/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
index cbc7748..c3f913e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
@@ -23,9 +23,14 @@ import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.optimiza
 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.AndStep;
+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.FilterStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.TailGlobalStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
@@ -71,7 +76,13 @@ public final class InlineFilterStrategy extends AbstractTraversalStrategy<Traver
             // filter(x.y) --> x.y
             for (final TraversalFilterStep<?> step : TraversalHelper.getStepsOfClass(TraversalFilterStep.class,
traversal)) {
                 final Traversal.Admin<?, ?> childTraversal = step.getLocalChildren().get(0);
-                if (TraversalHelper.allStepsInstanceOf(childTraversal, FilterStep.class))
{
+                if (TraversalHelper.hasAllStepsOfClass(childTraversal, FilterStep.class)
&&
+                        !TraversalHelper.hasStepOfClass(childTraversal,
+                                DropStep.class,
+                                RangeGlobalStep.class,
+                                TailGlobalStep.class,
+                                DedupGlobalStep.class,
+                                LambdaHolder.class)) {
                     changed = true;
                     TraversalHelper.applySingleLevelStrategies(traversal, childTraversal,
InlineFilterStrategy.class);
                     final Step<?, ?> finalStep = childTraversal.getEndStep();
@@ -82,7 +93,20 @@ public final class InlineFilterStrategy extends AbstractTraversalStrategy<Traver
             }
             // and(x,y) --> x.y
             for (final AndStep<?> step : TraversalHelper.getStepsOfClass(AndStep.class,
traversal)) {
-                if (!step.getLocalChildren().stream().filter(t -> !TraversalHelper.allStepsInstanceOf(t,
FilterStep.class)).findAny().isPresent()) {
+                boolean process = true;
+                for (final Traversal.Admin<?, ?> childTraversal : step.getLocalChildren())
{
+                    if (!TraversalHelper.hasAllStepsOfClass(childTraversal, FilterStep.class)
||
+                            TraversalHelper.hasStepOfClass(childTraversal,
+                                    DropStep.class,
+                                    RangeGlobalStep.class,
+                                    TailGlobalStep.class,
+                                    DedupGlobalStep.class,
+                                    LambdaHolder.class)) {
+                        process = false;
+                        break;
+                    }
+                }
+                if (process) {
                     changed = true;
                     final List<Traversal.Admin<?, ?>> childTraversals = (List)
step.getLocalChildren();
                     Step<?, ?> finalStep = null;
@@ -105,7 +129,7 @@ public final class InlineFilterStrategy extends AbstractTraversalStrategy<Traver
                     if (null != startLabel) {
                         for (final Traversal.Admin<?, ?> matchTraversal : new ArrayList<>(step.getGlobalChildren()))
{
                             if (!(step.getPreviousStep() instanceof EmptyStep) &&
-                                    TraversalHelper.allStepsInstanceOf(matchTraversal,
+                                    TraversalHelper.hasAllStepsOfClass(matchTraversal,
                                             HasStep.class,
                                             MatchStep.MatchStartStep.class,
                                             MatchStep.MatchEndStep.class) &&
@@ -128,6 +152,7 @@ public final class InlineFilterStrategy extends AbstractTraversalStrategy<Traver
                 }
             }
         }
+
     }
 
     private static final String determineStartLabelForHasPullOut(final MatchStep<?, ?>
matchStep) {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bb5e71be/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
index d38ac6e..2192666 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
@@ -579,7 +579,7 @@ public final class TraversalHelper {
         }
     }
 
-    public static boolean allStepsInstanceOf(final Traversal.Admin<?, ?> traversal,
final Class<?>... classesToCheck) {
+    public static boolean hasAllStepsOfClass(final Traversal.Admin<?, ?> traversal,
final Class<?>... classesToCheck) {
         for (final Step step : traversal.getSteps()) {
             boolean foundInstance = false;
             for (final Class<?> classToCheck : classesToCheck) {
@@ -594,6 +594,16 @@ public final class TraversalHelper {
         return true;
     }
 
+    public static boolean hasStepOfClass(final Traversal.Admin<?, ?> traversal, final
Class<?>... classesToCheck) {
+        for (final Step<?, ?> step : traversal.getSteps()) {
+            for (final Class<?> classToCheck : classesToCheck) {
+                if (classToCheck.isInstance(step))
+                    return true;
+            }
+        }
+        return false;
+    }
+
     public static void applySingleLevelStrategies(final Traversal.Admin<?, ?> parentTraversal,
final Traversal.Admin<?, ?> childTraversal, final Class<? extends TraversalStrategy>
stopAfterStrategy) {
         childTraversal.setStrategies(parentTraversal.getStrategies());
         childTraversal.setSideEffects(parentTraversal.getSideEffects());

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/bb5e71be/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
index e9e605a..aeae593 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
@@ -32,11 +32,15 @@ import java.util.Arrays;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.V;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.and;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.as;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.dedup;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.drop;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.filter;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.limit;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.map;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.match;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.tail;
 import static org.junit.Assert.assertEquals;
 
 /**
@@ -67,8 +71,8 @@ public class InlineFilterStrategyTest {
                 {filter(out("knows")), filter(out("knows"))},
                 {filter(has("age", P.gt(10))).as("a"), has("age", P.gt(10)).as("a")},
                 {filter(has("age", P.gt(10)).as("b")).as("a"), has("age", P.gt(10)).as("b",
"a")},
-                {filter(has("age", P.gt(10))), has("age", P.gt(10))},
-                {filter(and(has("age", P.gt(10)), has("name", "marko"))), has("age", P.gt(10)).has("name",
"marko")},
+                {filter(has("age", P.gt(10)).as("a")), has("age", P.gt(10)).as("a")},
+                {filter(and(has("age", P.gt(10)).as("a"), has("name", "marko"))), has("age",
P.gt(10)).as("a").has("name", "marko")},
                 //
                 {and(has("age", P.gt(10)), filter(has("age", 22))), has("age", P.gt(10)).has("age",
22)},
                 {and(has("age", P.gt(10)).as("a"), and(filter(has("age", 22).as("b")).as("c"),
has("name", "marko").as("d"))), has("age", P.gt(10)).as("a").has("age", 22).as("b", "c").has("name",
"marko").as("d")},
@@ -79,6 +83,11 @@ public class InlineFilterStrategyTest {
                 {map(match(as("a").has("age", 10), as("a").filter(has("name")).as("b"))),
map(match(as("a").has("age", 10), as("a").has("name").as("b")))},
                 {V().match(as("a").has("age", 10)), V().as("a").has("age", 10)},
                 {V().match(as("a").has("age", 10).as("b"), as("a").filter(has("name")).as("b")),
V().as("a").has("age", 10).as("b").match(as("a").has("name").as("b"))},
+                //
+                {filter(dedup()), filter(dedup())},
+                {filter(filter(drop())), filter(drop())},
+                {and(has("name"), limit(10).has("age")), and(has("name"), limit(10).has("age"))},
+                {filter(tail(10).as("a")), filter(tail(10).as("a"))},
         });
     }
 }


Mime
View raw message