tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dkupp...@apache.org
Subject [06/12] incubator-tinkerpop git commit: Covered a lot more query pattens in `RangeByIsCountStrategy`.
Date Fri, 27 May 2016 11:48:33 GMT
Covered a lot more query pattens in `RangeByIsCountStrategy`.


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

Branch: refs/heads/master
Commit: 498585b5311f45fbda97b4fa863fd08090df8965
Parents: d55897a
Author: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Authored: Thu May 26 14:58:12 2016 +0200
Committer: Daniel Kuppitz <daniel_kuppitz@hotmail.com>
Committed: Fri May 27 13:25:37 2016 +0200

----------------------------------------------------------------------
 .../optimization/RangeByIsCountStrategy.java       | 17 ++++++++++++++---
 .../optimization/RangeByIsCountStrategyTest.java   | 16 ++++++++++++----
 2 files changed, 26 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/498585b5/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java
index 2994085..09aa730 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategy.java
@@ -25,10 +25,13 @@ 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.dsl.graph.__;
+import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
 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.RangeGlobalStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountGlobalStep;
+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.util.ConnectiveP;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
@@ -70,6 +73,7 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
 
     @Override
     public void apply(final Traversal.Admin<?, ?> traversal) {
+        final TraversalParent parent = traversal.getParent();
         int size = traversal.getSteps().size();
         Step prev = null;
         for (int i = 0; i < size; i++) {
@@ -89,8 +93,11 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                             final Long highRangeCandidate = ((Number) value).longValue()
+ highRangeOffset;
                             final boolean update = highRange == null || highRangeCandidate
> highRange;
                             if (update) {
+                                final boolean isNested = !(parent instanceof EmptyStep);
                                 highRange = highRangeCandidate;
                                 useNotStep = curr.getLabels().isEmpty() && next.getLabels().isEmpty()
+                                        && (!isNested || parent instanceof SideEffectStep)
+                                        && next.getNextStep() instanceof EmptyStep
                                         && ((highRange <= 1L && predicate.equals(Compare.lt))
                                         || (highRange == 1L && (predicate.equals(Compare.eq)
|| predicate.equals(Compare.lte))));
                             }
@@ -111,9 +118,13 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                             traversal.asAdmin().removeStep(next); // IsStep
                             traversal.asAdmin().removeStep(curr); // CountStep
                             size -= 2;
-                            final Traversal.Admin inner = __.start().asAdmin();
-                            TraversalHelper.insertAfterStep(prev, inner.getStartStep(), inner);
-                            TraversalHelper.replaceStep(prev, new NotStep<>(traversal,
inner), traversal);
+                            if (prev != null) {
+                                final Traversal.Admin inner = __.start().asAdmin();
+                                TraversalHelper.insertAfterStep(prev, inner.getStartStep(),
inner);
+                                TraversalHelper.replaceStep(prev, new NotStep<>(traversal,
inner), traversal);
+                            } else {
+                                traversal.asAdmin().addStep(new NotStep<>(traversal,
__.identity()));
+                            }
                         } else {
                             TraversalHelper.insertBeforeStep(new RangeGlobalStep<>(traversal,
0L, highRange), curr, traversal);
                         }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/498585b5/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategyTest.java
index f07c267..e62c3a6 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/RangeByIsCountStrategyTest.java
@@ -124,10 +124,12 @@ public class RangeByIsCountStrategyTest {
         static Iterable<Object[]> generateTestParameters() {
 
             return Arrays.asList(new Traversal[][]{
+                    {__.count().is(0), __.not(__.identity())},
+                    {__.count().is(1), __.limit(2).count().is(1)},
                     {__.out().count().is(0), __.not(__.out())},
-                    {__.out().count().is(lt(1)), __.not(__.out())},
-                    {__.out().count().is(lte(0)), __.not(__.out())},
-                    {__.out().count().is(0).as("a"), __.out().limit(1).count().is(0).as("a")},
+                    {__.outE().count().is(lt(1)), __.not(__.outE())},
+                    {__.both().count().is(lte(0)), __.not(__.both())},
+                    {__.store("x").count().is(0).as("a"), __.store("x").limit(1).count().is(0).as("a")},
                     {__.out().count().as("a").is(0), __.out().limit(1).count().as("a").is(0)},
                     {__.out().count().is(neq(4)), __.out().limit(5).count().is(neq(4))},
                     {__.out().count().is(lte(3)), __.out().limit(4).count().is(lte(3))},
@@ -137,7 +139,13 @@ public class RangeByIsCountStrategyTest {
                     {__.out().count().is(inside(2, 4)), __.out().limit(4).count().is(inside(2,
4))},
                     {__.out().count().is(outside(2, 4)), __.out().limit(5).count().is(outside(2,
4))},
                     {__.out().count().is(within(2, 6, 4)), __.out().limit(7).count().is(within(2,
6, 4))},
-                    {__.out().count().is(without(2, 6, 4)), __.out().limit(6).count().is(without(2,
6, 4))}});
+                    {__.out().count().is(without(2, 6, 4)), __.out().limit(6).count().is(without(2,
6, 4))},
+                    {__.map(__.count().is(0)), __.map(__.count().limit(1).is(0))},
+                    {__.flatMap(__.count().is(0)), __.flatMap(__.count().limit(1).is(0))},
+                    {__.sideEffect(__.count().is(0)), __.sideEffect(__.not(__.identity()))},
+                    {__.branch(__.count().is(0)), __.branch(__.count().limit(1).is(0))},
+                    {__.count().is(0).store("x"), __.limit(1).count().is(0).store("x")},
+            });
         }
     }
 }


Mime
View raw message