You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by dk...@apache.org on 2016/05/27 11:26:32 UTC

[01/11] incubator-tinkerpop git commit: Updated CHANGELOG

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/tp31 63e849c00 -> 5d38bbeb5


Updated CHANGELOG


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

Branch: refs/heads/tp31
Commit: a73ec2ff82697439a0f684045228a854ba2ef374
Parents: 572736d
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed May 25 21:24:58 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:34 2016 +0200

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/a73ec2ff/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 3d1f51f..9cd6998 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/
 TinkerPop 3.1.3 (NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Optimized a few special cases in `RangeByIsCountStrategy`.
 * Named the thread pool used by Gremlin Server sessions: "gremlin-server-session-$n".
 * Fixed a bug in `BulkSet.equals()` which made itself apparent when using `store()` and `aggregate()` with labeled `cap()`.
 * Ensured that all asserts of vertex and edge counts were being applied properly in the test suite.


[09/11] incubator-tinkerpop git commit: Fixed some typos.

Posted by dk...@apache.org.
Fixed some typos.


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

Branch: refs/heads/tp31
Commit: 05ab5992cbf40d1e1e1908089d3fb62f8578ea44
Parents: 70e8c2a
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu May 26 15:44:23 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:38 2016 +0200

----------------------------------------------------------------------
 .../strategy/optimization/RangeByIsCountStrategyTest.java | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/05ab5992/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 820d4cc..8b42e7f 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
@@ -107,7 +107,7 @@ public class RangeByIsCountStrategyTest {
 
         protected TraversalEngine traversalEngine;
 
-        void applyAdjacentToIncidentStrategy(final Traversal traversal) {
+        void applyRangeByIsCountStrategy(final Traversal traversal) {
             final TraversalStrategies strategies = new DefaultTraversalStrategies();
             strategies.addStrategies(RangeByIsCountStrategy.instance());
 
@@ -117,7 +117,7 @@ public class RangeByIsCountStrategyTest {
         }
 
         public void doTest(final Traversal traversal, final Traversal optimized) {
-            applyAdjacentToIncidentStrategy(traversal);
+            applyRangeByIsCountStrategy(traversal);
             assertEquals(optimized, traversal);
         }
 
@@ -140,10 +140,10 @@ public class RangeByIsCountStrategyTest {
                     {__.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))},
-                    {__.map(__.count().is(0)), __.map(__.count().limit(1).is(0))},
-                    {__.flatMap(__.count().is(0)), __.flatMap(__.count().limit(1).is(0))},
+                    {__.map(__.count().is(0)), __.map(__.limit(1).count().is(0))},
+                    {__.flatMap(__.count().is(0)), __.flatMap(__.limit(1).count().is(0))},
                     {__.sideEffect(__.count().is(0)), __.sideEffect(__.not(__.identity()))},
-                    {__.branch(__.count().is(0)), __.branch(__.count().limit(1).is(0))},
+                    {__.branch(__.count().is(0)), __.branch(__.limit(1).count().is(0))},
                     {__.count().is(0).store("x"), __.limit(1).count().is(0).store("x")},
                     {__.repeat(__.out()).until(__.outE().count().is(0)), __.repeat(__.out()).until(__.not(__.outE()))},
                     {__.repeat(__.out()).emit(__.outE().count().is(0)), __.repeat(__.out()).emit(__.not(__.outE()))},


[02/11] incubator-tinkerpop git commit: Tweaked `RangeByIsCountStrategy`. The pattern `outE().count().is(0)` is now replaced by `not(outE())`

Posted by dk...@apache.org.
Tweaked `RangeByIsCountStrategy`. The pattern `outE().count().is(0)` is now replaced by `not(outE())`


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

Branch: refs/heads/tp31
Commit: 572736dacfde461e4310a36734c5186e8bcff151
Parents: 63e849c
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed May 25 21:13:48 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:34 2016 +0200

----------------------------------------------------------------------
 .../optimization/RangeByIsCountStrategy.java    |  27 +++--
 .../RangeByIsCountStrategyTest.java             | 105 ++++++++++++++++++-
 .../structure/TinkerGraphPlayTest.java          |  43 ++++----
 3 files changed, 144 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/572736da/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 f2d60b1..f3168a3 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
@@ -18,18 +18,20 @@
  */
 package org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization;
 
+import org.apache.tinkerpop.gremlin.process.traversal.Compare;
+import org.apache.tinkerpop.gremlin.process.traversal.Contains;
+import org.apache.tinkerpop.gremlin.process.traversal.P;
 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.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.strategy.AbstractTraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.util.ConnectiveP;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import org.apache.tinkerpop.gremlin.process.traversal.Compare;
-import org.apache.tinkerpop.gremlin.process.traversal.Contains;
-import org.apache.tinkerpop.gremlin.process.traversal.P;
 
 import java.util.Collection;
 import java.util.Collections;
@@ -47,7 +49,7 @@ import java.util.function.BiPredicate;
  *
  * @author Daniel Kuppitz (http://gremlin.guru)
  * @example <pre>
- * __.outE().count().is(0)      // is replaced by __.outE().limit(1).count().is(0)
+ * __.outE().count().is(0)      // is replaced by __.not(outE())
  * __.outE().count().is(lt(3))  // is replaced by __.outE().limit(3).count().is(lt(3))
  * __.outE().count().is(gt(3))  // is replaced by __.outE().limit(4).count().is(gt(3))
  * </pre>
@@ -78,6 +80,7 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                     final IsStep isStep = (IsStep) next;
                     final P isStepPredicate = isStep.getPredicate();
                     Long highRange = null;
+                    boolean useNotStep = false;
                     for (P p : isStepPredicate instanceof ConnectiveP ? ((ConnectiveP<?>) isStepPredicate).getPredicates() : Collections.singletonList(isStepPredicate)) {
                         final Object value = p.getValue();
                         final BiPredicate predicate = p.getBiPredicate();
@@ -85,7 +88,11 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                             final long highRangeOffset = INCREASED_OFFSET_SCALAR_PREDICATES.contains(predicate) ? 1L : 0L;
                             final Long highRangeCandidate = ((Number) value).longValue() + highRangeOffset;
                             final boolean update = highRange == null || highRangeCandidate > highRange;
-                            if (update) highRange = highRangeCandidate;
+                            if (update) {
+                                highRange = highRangeCandidate;
+                                useNotStep = (highRange <= 1L && predicate.equals(Compare.lt)) ||
+                                        (highRange == 1L && (predicate.equals(Compare.eq) || predicate.equals(Compare.lte)));
+                            }
                         } else {
                             final Long highRangeOffset = RANGE_PREDICATES.get(predicate);
                             if (value instanceof Collection && highRangeOffset != null) {
@@ -99,7 +106,15 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                         }
                     }
                     if (highRange != null) {
-                        TraversalHelper.insertBeforeStep(new RangeGlobalStep<>(traversal, 0L, highRange), curr, traversal);
+                        if (useNotStep) {
+                            traversal.asAdmin().removeStep(next); // IsStep
+                            traversal.asAdmin().removeStep(curr); // CountStep
+                            final Traversal.Admin inner = __.start().asAdmin();
+                            TraversalHelper.insertAfterStep(prev, inner.getStartStep(), inner);
+                            TraversalHelper.replaceStep(prev, new NotStep<>(traversal, inner), traversal);
+                        } else {
+                            TraversalHelper.insertBeforeStep(new RangeGlobalStep<>(traversal, 0L, highRange), curr, traversal);
+                        }
                         i++;
                     }
                 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/572736da/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 1642b41..a72df8e 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
@@ -22,6 +22,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
+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.filter.TraversalFilterStep;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies;
@@ -36,7 +37,16 @@ import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
-import static org.apache.tinkerpop.gremlin.process.traversal.P.*;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.eq;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.gt;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.gte;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.inside;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.lt;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.lte;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.neq;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.outside;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.within;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.without;
 import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -78,6 +88,32 @@ public class RangeByIsCountStrategyTest {
     }
 
     @RunWith(Parameterized.class)
+    public static class StandardNotTest extends AbstractRangeByIsCountStrategyTest {
+
+        @Parameterized.Parameters(name = "{0}")
+        public static Iterable<Object[]> data() {
+            return generateNotTestParameters();
+        }
+
+        @Parameterized.Parameter(value = 0)
+        public String name;
+
+        @Parameterized.Parameter(value = 1)
+        public Object predicate;
+
+        @Before
+        public void setup() {
+            this.traversalEngine = mock(TraversalEngine.class);
+            when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.STANDARD);
+        }
+
+        @Test
+        public void shouldApplyStrategy() {
+            doTest(predicate);
+        }
+    }
+
+    @RunWith(Parameterized.class)
     public static class ComputerTest extends AbstractRangeByIsCountStrategyTest {
 
         @Parameterized.Parameters(name = "{0}")
@@ -106,6 +142,32 @@ public class RangeByIsCountStrategyTest {
         }
     }
 
+    @RunWith(Parameterized.class)
+    public static class ComputerNotTest extends AbstractRangeByIsCountStrategyTest {
+
+        @Parameterized.Parameters(name = "{0}")
+        public static Iterable<Object[]> data() {
+            return generateNotTestParameters();
+        }
+
+        @Parameterized.Parameter(value = 0)
+        public String name;
+
+        @Parameterized.Parameter(value = 1)
+        public Object predicate;
+
+        @Before
+        public void setup() {
+            this.traversalEngine = mock(TraversalEngine.class);
+            when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
+        }
+
+        @Test
+        public void shouldApplyStrategy() {
+            doTest(predicate);
+        }
+    }
+
     public static class SpecificComputerTest extends AbstractRangeByIsCountStrategyTest {
 
         @Before
@@ -115,16 +177,31 @@ public class RangeByIsCountStrategyTest {
         }
 
         @Test
-        public void nestedCountEqualsNullShouldLimitToOne() {
+        public void nestedCountEqualsOneShouldLimitToTwo() {
             final AtomicInteger counter = new AtomicInteger(0);
-            final Traversal traversal = __.out().where(__.outE("created").count().is(0));
+            final Traversal traversal = __.out().where(__.outE("created").count().is(1));
             applyRangeByIsCountStrategy(traversal);
 
             final TraversalFilterStep filterStep = TraversalHelper.getStepsOfClass(TraversalFilterStep.class, traversal.asAdmin()).stream().findFirst().get();
             final Traversal nestedTraversal = (Traversal) filterStep.getLocalChildren().get(0);
             TraversalHelper.getStepsOfClass(RangeGlobalStep.class, nestedTraversal.asAdmin()).stream().forEach(step -> {
                 assertEquals(0, step.getLowRange());
-                assertEquals(1, step.getHighRange());
+                assertEquals(2, step.getHighRange());
+                counter.incrementAndGet();
+            });
+            assertEquals(1, counter.get());
+        }
+
+        @Test
+        public void nestedCountEqualsNullShouldUseNotStep() {
+            final AtomicInteger counter = new AtomicInteger(0);
+            final Traversal traversal = __.out().where(__.outE("created").count().is(0));
+            applyRangeByIsCountStrategy(traversal);
+
+            final TraversalFilterStep filterStep = TraversalHelper.getStepsOfClass(TraversalFilterStep.class, traversal.asAdmin()).stream().findFirst().get();
+            final Traversal nestedTraversal = (Traversal) filterStep.getLocalChildren().get(0);
+            TraversalHelper.getStepsOfClass(NotStep.class, nestedTraversal.asAdmin()).stream().forEach(step -> {
+                assertEquals(__.outE("created"), step.getLocalChildren().get(0));
                 counter.incrementAndGet();
             });
             assertEquals(1, counter.get());
@@ -162,10 +239,20 @@ public class RangeByIsCountStrategyTest {
             assertEquals(1, counter.intValue());
         }
 
+        public void doTest(final Object predicate) {
+            final Traversal traversal = __.out().count().is(predicate);
+
+            applyRangeByIsCountStrategy(traversal);
+
+            final List<NotStep> steps = TraversalHelper.getStepsOfClass(NotStep.class, traversal.asAdmin());
+            assertEquals(1, steps.size());
+
+            steps.forEach(step -> assertEquals(__.out(), step.getLocalChildren().get(0)));
+        }
+
         static Iterable<Object[]> generateTestParameters() {
 
             return Arrays.asList(new Object[][]{
-                    {"countEqualsNullShouldLimitToOne", eq(0l), 1l},
                     {"countNotEqualsFourShouldLimitToFive", neq(4l), 5l},
                     {"countLessThanOrEqualThreeShouldLimitToFour", lte(3l), 4l},
                     {"countLessThanThreeShouldLimitToThree", lt(3l), 3l},
@@ -176,5 +263,13 @@ public class RangeByIsCountStrategyTest {
                     {"countWithinTwoSixFourShouldLimitToSeven", within(2l, 6l, 4l), 7l},
                     {"countWithoutTwoSixFourShouldLimitToSix", without(2l, 6l, 4l), 6l}});
         }
+
+        static Iterable<Object[]> generateNotTestParameters() {
+
+            return Arrays.asList(new Object[][]{
+                    {"countEqualsNullShouldUseNotStep", eq(0l)},
+                    {"countLessThanOneShouldUseNotStep", lt(1l)},
+                    {"countLessThanOrEqualNullShouldUseNotStep", lte(0l)}});
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/572736da/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 c9f3e6d..269f400 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
@@ -18,7 +18,6 @@
  */
 package org.apache.tinkerpop.gremlin.tinkergraph.structure;
 
-import org.apache.tinkerpop.gremlin.process.computer.bulkloading.BulkLoaderVertexProgram;
 import org.apache.tinkerpop.gremlin.process.traversal.Operator;
 import org.apache.tinkerpop.gremlin.process.traversal.Order;
 import org.apache.tinkerpop.gremlin.process.traversal.P;
@@ -32,20 +31,30 @@ import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.io.graphml.GraphMLIo;
-import org.apache.tinkerpop.gremlin.structure.util.GraphFactory;
 import org.apache.tinkerpop.gremlin.util.TimeUtil;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
 import java.util.Arrays;
 import java.util.List;
-import java.util.function.Function;
 import java.util.function.Supplier;
 
-import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.lt;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.as;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.both;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.choose;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.count;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.fold;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.outE;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.union;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.valueMap;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.values;
 
 /**
  * @author Stephen Mallette (http://stephen.genoprime.com)
@@ -71,7 +80,7 @@ public class TinkerGraphPlayTest {
         graph.io(GraphMLIo.build()).readGraph("data/grateful-dead.xml");
         /////////
 
-        g.V().group().by(T.label).by(values("name")).forEachRemaining(x->logger.info(x.toString()));
+        g.V().group().by(T.label).by(values("name")).forEachRemaining(x -> logger.info(x.toString()));
 
         logger.info("group: " + g.V().both("followedBy").both("followedBy").group().by("songType").by(count()).next());
         logger.info("groupV3d0: " + g.V().both("followedBy").both("followedBy").groupV3d0().by("songType").by().by(__.count(Scope.local)).next());
@@ -126,7 +135,7 @@ public class TinkerGraphPlayTest {
         v7.addEdge("link", v9, "weight", 1f);
         v8.addEdge("link", v9, "weight", 7f);
 
-        g.traversal().withSack(Float.MIN_VALUE).V(v1).repeat(outE().sack(Operator.max, "weight").inV()).times(5).sack().forEachRemaining(x->logger.info(x.toString()));
+        g.traversal().withSack(Float.MIN_VALUE).V(v1).repeat(outE().sack(Operator.max, "weight").inV()).times(5).sack().forEachRemaining(x -> logger.info(x.toString()));
     }
 
    /* @Test
@@ -200,18 +209,12 @@ public class TinkerGraphPlayTest {
     @Ignore
     public void testPlayDK() throws Exception {
 
-        new File("/tmp/tinkergraph2.kryo").deleteOnExit();
-        new File("/tmp/tinkergraph3.kryo").deleteOnExit();
-
-        final Graph graph1 = TinkerFactory.createModern();
-        final Graph graph2 = GraphFactory.open("/tmp/graph2.properties");
-        TinkerFactory.generateModern((TinkerGraph) graph2);
-        graph2.close();
-
-        logger.info("graph1 -> graph2");
-        graph1.compute().workers(1).program(BulkLoaderVertexProgram.build().userSuppliedIds(true).writeGraph("/tmp/graph2.properties").create(graph1)).submit().get();
-        logger.info("graph1 -> graph3");
-        graph1.compute().workers(1).program(BulkLoaderVertexProgram.build().userSuppliedIds(true).writeGraph("/tmp/graph3.properties").create(graph1)).submit().get();
+        Graph graph = TinkerGraph.open();
+        GraphTraversalSource g = graph.traversal();
+        graph.io(GraphMLIo.build()).readGraph("/projects/apache/incubator-tinkerpop/data/grateful-dead.xml");
+        System.out.println(g.V().filter(outE("sungBy").count().is(0)).explain());
+        System.out.println(g.V().filter(outE("sungBy").count().is(lt(1))).explain());
+        System.out.println(g.V().filter(outE("sungBy").count().is(1)).explain());
     }
 
     @Test
@@ -256,7 +259,7 @@ public class TinkerGraphPlayTest {
 
         logger.info(traversal.get().toString());
         logger.info(traversal.get().iterate().toString());
-        traversal.get().forEachRemaining(x->logger.info(x.toString()));
+        traversal.get().forEachRemaining(x -> logger.info(x.toString()));
 
     }
 


[05/11] incubator-tinkerpop git commit: Don't over-optimize in `RangeByIsCountStrategy` if `count()` or `is()` is labeled.

Posted by dk...@apache.org.
Don't over-optimize in `RangeByIsCountStrategy` if `count()` or `is()` is labeled.


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

Branch: refs/heads/tp31
Commit: d55897afcd3833d9161d0871ad46cc21cf3db7ce
Parents: 51f55df
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu May 26 11:13:17 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:37 2016 +0200

----------------------------------------------------------------------
 .../traversal/strategy/optimization/RangeByIsCountStrategy.java | 5 +++--
 .../strategy/optimization/RangeByIsCountStrategyTest.java       | 2 ++
 2 files changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d55897af/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 efa79e6..2994085 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
@@ -90,8 +90,9 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                             final boolean update = highRange == null || highRangeCandidate > highRange;
                             if (update) {
                                 highRange = highRangeCandidate;
-                                useNotStep = (highRange <= 1L && predicate.equals(Compare.lt)) ||
-                                        (highRange == 1L && (predicate.equals(Compare.eq) || predicate.equals(Compare.lte)));
+                                useNotStep = curr.getLabels().isEmpty() && next.getLabels().isEmpty()
+                                        && ((highRange <= 1L && predicate.equals(Compare.lt))
+                                        || (highRange == 1L && (predicate.equals(Compare.eq) || predicate.equals(Compare.lte))));
                             }
                         } else {
                             final Long highRangeOffset = RANGE_PREDICATES.get(predicate);

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/d55897af/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 b6d0e27..f07c267 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
@@ -127,6 +127,8 @@ public class RangeByIsCountStrategyTest {
                     {__.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")},
+                    {__.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))},
                     {__.out().count().is(lt(3)), __.out().limit(3).count().is(lt(3))},


[04/11] incubator-tinkerpop git commit: Increase step offset by 2 if `foo.count().is(0)` was replaced by `not(foo)`.

Posted by dk...@apache.org.
Increase step offset by 2 if `foo.count().is(0)` was replaced by `not(foo)`.


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

Branch: refs/heads/tp31
Commit: bffa77f22dda6831c32aa70cd2f1f32d9652993f
Parents: a73ec2f
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed May 25 21:33:44 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:36 2016 +0200

----------------------------------------------------------------------
 .../traversal/strategy/optimization/RangeByIsCountStrategy.java     | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/bffa77f2/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 f3168a3..1b544c2 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
@@ -109,6 +109,7 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                         if (useNotStep) {
                             traversal.asAdmin().removeStep(next); // IsStep
                             traversal.asAdmin().removeStep(curr); // CountStep
+                            i += 2;
                             final Traversal.Admin inner = __.start().asAdmin();
                             TraversalHelper.insertAfterStep(prev, inner.getStartStep(), inner);
                             TraversalHelper.replaceStep(prev, new NotStep<>(traversal, inner), traversal);


[10/11] incubator-tinkerpop git commit: Fixed `DefaultTraversal`'s hash code calculation.

Posted by dk...@apache.org.
Fixed `DefaultTraversal`'s hash code calculation.


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

Branch: refs/heads/tp31
Commit: ef53888c9e5bcd16445c129d0692ec7c73d5343a
Parents: 05ab599
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu May 26 15:55:02 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:38 2016 +0200

----------------------------------------------------------------------
 .../gremlin/process/traversal/util/DefaultTraversal.java          | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/ef53888c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
index 43fc692..977e4ac 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversal.java
@@ -303,9 +303,10 @@ public class DefaultTraversal<S, E> implements Traversal.Admin<S, E> {
 
     @Override
     public int hashCode() {
+        int index = 0;
         int result = this.getClass().hashCode();
         for (final Step step : this.asAdmin().getSteps()) {
-            result ^= step.hashCode();
+            result ^= Integer.rotateLeft(step.hashCode(), index++);
         }
         return result;
     }


[08/11] incubator-tinkerpop git commit: Covered a lot more query pattens in `RangeByIsCountStrategy`.

Posted by dk...@apache.org.
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/tp31
Commit: 498585b5311f45fbda97b4fa863fd08090df8965
Parents: d55897a
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu May 26 14:58:12 2016 +0200
Committer: Daniel Kuppitz <da...@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")},
+            });
         }
     }
 }


[11/11] incubator-tinkerpop git commit: Forgot to handle `FilterSteps`.

Posted by dk...@apache.org.
Forgot to handle `FilterSteps`.


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

Branch: refs/heads/tp31
Commit: 5d38bbeb591a49f5c47ed0aa7d9aece12cf3dd21
Parents: ef53888
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu May 26 22:18:25 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:39 2016 +0200

----------------------------------------------------------------------
 .../strategy/optimization/RangeByIsCountStrategy.java     | 10 +++++-----
 .../strategy/optimization/RangeByIsCountStrategyTest.java |  1 +
 2 files changed, 6 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/5d38bbeb/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 835a8f9..451d561 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
@@ -27,6 +27,7 @@ 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.branch.RepeatStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep;
 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;
@@ -95,17 +96,16 @@ 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);
-                                if (isNested) {
+                                if (parent instanceof EmptyStep) {
+                                    useNotStep = true;
+                                } else {
                                     if (parent instanceof RepeatStep) {
                                         final RepeatStep repeatStep = (RepeatStep) parent;
                                         useNotStep = Objects.equals(traversal, repeatStep.getUntilTraversal())
                                                 || Objects.equals(traversal, repeatStep.getEmitTraversal());
                                     } else {
-                                        useNotStep = parent instanceof SideEffectStep;
+                                        useNotStep = parent instanceof FilterStep || parent instanceof SideEffectStep;
                                     }
-                                } else {
-                                    useNotStep = true;
                                 }
                                 highRange = highRangeCandidate;
                                 useNotStep &= curr.getLabels().isEmpty() && next.getLabels().isEmpty()

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/5d38bbeb/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 8b42e7f..03d5176 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
@@ -142,6 +142,7 @@ public class RangeByIsCountStrategyTest {
                     {__.out().count().is(without(2, 6, 4)), __.out().limit(6).count().is(without(2, 6, 4))},
                     {__.map(__.count().is(0)), __.map(__.limit(1).count().is(0))},
                     {__.flatMap(__.count().is(0)), __.flatMap(__.limit(1).count().is(0))},
+                    {__.filter(__.count().is(0)), __.filter(__.not(__.identity()))},
                     {__.sideEffect(__.count().is(0)), __.sideEffect(__.not(__.identity()))},
                     {__.branch(__.count().is(0)), __.branch(__.limit(1).count().is(0))},
                     {__.count().is(0).store("x"), __.limit(1).count().is(0).store("x")},


[07/11] incubator-tinkerpop git commit: Special `RangeByIsCountStrategy` handling for `repeat()`'s `emit()` and `until()`.

Posted by dk...@apache.org.
Special `RangeByIsCountStrategy` handling for `repeat()`'s `emit()` and `until()`.


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

Branch: refs/heads/tp31
Commit: 70e8c2a682e9b6849e4e893c2109b7d924292a2d
Parents: 498585b
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu May 26 15:14:48 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:37 2016 +0200

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


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/70e8c2a6/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 09aa730..835a8f9 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
@@ -26,6 +26,7 @@ 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.branch.RepeatStep;
 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;
@@ -41,6 +42,7 @@ import java.util.Collections;
 import java.util.EnumSet;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Set;
 import java.util.function.BiPredicate;
 
@@ -94,9 +96,19 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                             final boolean update = highRange == null || highRangeCandidate > highRange;
                             if (update) {
                                 final boolean isNested = !(parent instanceof EmptyStep);
+                                if (isNested) {
+                                    if (parent instanceof RepeatStep) {
+                                        final RepeatStep repeatStep = (RepeatStep) parent;
+                                        useNotStep = Objects.equals(traversal, repeatStep.getUntilTraversal())
+                                                || Objects.equals(traversal, repeatStep.getEmitTraversal());
+                                    } else {
+                                        useNotStep = parent instanceof SideEffectStep;
+                                    }
+                                } else {
+                                    useNotStep = true;
+                                }
                                 highRange = highRangeCandidate;
-                                useNotStep = curr.getLabels().isEmpty() && next.getLabels().isEmpty()
-                                        && (!isNested || parent instanceof SideEffectStep)
+                                useNotStep &= curr.getLabels().isEmpty() && next.getLabels().isEmpty()
                                         && next.getNextStep() instanceof EmptyStep
                                         && ((highRange <= 1L && predicate.equals(Compare.lt))
                                         || (highRange == 1L && (predicate.equals(Compare.eq) || predicate.equals(Compare.lte))));

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/70e8c2a6/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 e62c3a6..820d4cc 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
@@ -145,6 +145,8 @@ public class RangeByIsCountStrategyTest {
                     {__.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")},
+                    {__.repeat(__.out()).until(__.outE().count().is(0)), __.repeat(__.out()).until(__.not(__.outE()))},
+                    {__.repeat(__.out()).emit(__.outE().count().is(0)), __.repeat(__.out()).emit(__.not(__.outE()))},
             });
         }
     }


[06/11] incubator-tinkerpop git commit: More robust pattern for `RangeByIsCountStrategy`.

Posted by dk...@apache.org.
More robust pattern for `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/51f55df1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/51f55df1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/51f55df1

Branch: refs/heads/tp31
Commit: 51f55df12d42e72a8d859e1f5b27473e4bf71862
Parents: 041c033
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Thu May 26 11:03:52 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:37 2016 +0200

----------------------------------------------------------------------
 .../RangeByIsCountStrategyTest.java             | 180 +++----------------
 1 file changed, 23 insertions(+), 157 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/51f55df1/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 a72df8e..b6d0e27 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
@@ -22,11 +22,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
-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.filter.TraversalFilterStep;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies;
-import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.runners.Enclosed;
@@ -34,10 +30,7 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import java.util.Arrays;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
 
-import static org.apache.tinkerpop.gremlin.process.traversal.P.eq;
 import static org.apache.tinkerpop.gremlin.process.traversal.P.gt;
 import static org.apache.tinkerpop.gremlin.process.traversal.P.gte;
 import static org.apache.tinkerpop.gremlin.process.traversal.P.inside;
@@ -67,39 +60,10 @@ public class RangeByIsCountStrategyTest {
         }
 
         @Parameterized.Parameter(value = 0)
-        public String name;
+        public Traversal original;
 
         @Parameterized.Parameter(value = 1)
-        public Object predicate;
-
-        @Parameterized.Parameter(value = 2)
-        public long expectedHighRange;
-
-        @Before
-        public void setup() {
-            this.traversalEngine = mock(TraversalEngine.class);
-            when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.STANDARD);
-        }
-
-        @Test
-        public void shouldApplyStrategy() {
-            doTest(predicate, expectedHighRange);
-        }
-    }
-
-    @RunWith(Parameterized.class)
-    public static class StandardNotTest extends AbstractRangeByIsCountStrategyTest {
-
-        @Parameterized.Parameters(name = "{0}")
-        public static Iterable<Object[]> data() {
-            return generateNotTestParameters();
-        }
-
-        @Parameterized.Parameter(value = 0)
-        public String name;
-
-        @Parameterized.Parameter(value = 1)
-        public Object predicate;
+        public Traversal optimized;
 
         @Before
         public void setup() {
@@ -109,7 +73,7 @@ public class RangeByIsCountStrategyTest {
 
         @Test
         public void shouldApplyStrategy() {
-            doTest(predicate);
+            doTest(original, optimized);
         }
     }
 
@@ -122,39 +86,10 @@ public class RangeByIsCountStrategyTest {
         }
 
         @Parameterized.Parameter(value = 0)
-        public String name;
-
-        @Parameterized.Parameter(value = 1)
-        public Object predicate;
-
-        @Parameterized.Parameter(value = 2)
-        public long expectedHighRange;
-
-        @Before
-        public void setup() {
-            this.traversalEngine = mock(TraversalEngine.class);
-            when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
-        }
-
-        @Test
-        public void shouldApplyStrategy() {
-            doTest(predicate, expectedHighRange);
-        }
-    }
-
-    @RunWith(Parameterized.class)
-    public static class ComputerNotTest extends AbstractRangeByIsCountStrategyTest {
-
-        @Parameterized.Parameters(name = "{0}")
-        public static Iterable<Object[]> data() {
-            return generateNotTestParameters();
-        }
-
-        @Parameterized.Parameter(value = 0)
-        public String name;
+        public Traversal original;
 
         @Parameterized.Parameter(value = 1)
-        public Object predicate;
+        public Traversal optimized;
 
         @Before
         public void setup() {
@@ -164,47 +99,7 @@ public class RangeByIsCountStrategyTest {
 
         @Test
         public void shouldApplyStrategy() {
-            doTest(predicate);
-        }
-    }
-
-    public static class SpecificComputerTest extends AbstractRangeByIsCountStrategyTest {
-
-        @Before
-        public void setup() {
-            this.traversalEngine = mock(TraversalEngine.class);
-            when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
-        }
-
-        @Test
-        public void nestedCountEqualsOneShouldLimitToTwo() {
-            final AtomicInteger counter = new AtomicInteger(0);
-            final Traversal traversal = __.out().where(__.outE("created").count().is(1));
-            applyRangeByIsCountStrategy(traversal);
-
-            final TraversalFilterStep filterStep = TraversalHelper.getStepsOfClass(TraversalFilterStep.class, traversal.asAdmin()).stream().findFirst().get();
-            final Traversal nestedTraversal = (Traversal) filterStep.getLocalChildren().get(0);
-            TraversalHelper.getStepsOfClass(RangeGlobalStep.class, nestedTraversal.asAdmin()).stream().forEach(step -> {
-                assertEquals(0, step.getLowRange());
-                assertEquals(2, step.getHighRange());
-                counter.incrementAndGet();
-            });
-            assertEquals(1, counter.get());
-        }
-
-        @Test
-        public void nestedCountEqualsNullShouldUseNotStep() {
-            final AtomicInteger counter = new AtomicInteger(0);
-            final Traversal traversal = __.out().where(__.outE("created").count().is(0));
-            applyRangeByIsCountStrategy(traversal);
-
-            final TraversalFilterStep filterStep = TraversalHelper.getStepsOfClass(TraversalFilterStep.class, traversal.asAdmin()).stream().findFirst().get();
-            final Traversal nestedTraversal = (Traversal) filterStep.getLocalChildren().get(0);
-            TraversalHelper.getStepsOfClass(NotStep.class, nestedTraversal.asAdmin()).stream().forEach(step -> {
-                assertEquals(__.outE("created"), step.getLocalChildren().get(0));
-                counter.incrementAndGet();
-            });
-            assertEquals(1, counter.get());
+            doTest(original, optimized);
         }
     }
 
@@ -212,7 +107,7 @@ public class RangeByIsCountStrategyTest {
 
         protected TraversalEngine traversalEngine;
 
-        void applyRangeByIsCountStrategy(final Traversal traversal) {
+        void applyAdjacentToIncidentStrategy(final Traversal traversal) {
             final TraversalStrategies strategies = new DefaultTraversalStrategies();
             strategies.addStrategies(RangeByIsCountStrategy.instance());
 
@@ -221,55 +116,26 @@ public class RangeByIsCountStrategyTest {
             traversal.asAdmin().applyStrategies();
         }
 
-        public void doTest(final Object predicate, final long expectedHighRange) {
-            final AtomicInteger counter = new AtomicInteger(0);
-            final Traversal traversal = __.out().count().is(predicate);
-
-            applyRangeByIsCountStrategy(traversal);
-
-            final List<RangeGlobalStep> steps = TraversalHelper.getStepsOfClass(RangeGlobalStep.class, traversal.asAdmin());
-            assertEquals(1, steps.size());
-
-            steps.forEach(step -> {
-                assertEquals(0, step.getLowRange());
-                assertEquals(expectedHighRange, step.getHighRange());
-                counter.incrementAndGet();
-            });
-
-            assertEquals(1, counter.intValue());
-        }
-
-        public void doTest(final Object predicate) {
-            final Traversal traversal = __.out().count().is(predicate);
-
-            applyRangeByIsCountStrategy(traversal);
-
-            final List<NotStep> steps = TraversalHelper.getStepsOfClass(NotStep.class, traversal.asAdmin());
-            assertEquals(1, steps.size());
-
-            steps.forEach(step -> assertEquals(__.out(), step.getLocalChildren().get(0)));
+        public void doTest(final Traversal traversal, final Traversal optimized) {
+            applyAdjacentToIncidentStrategy(traversal);
+            assertEquals(optimized, traversal);
         }
 
         static Iterable<Object[]> generateTestParameters() {
 
-            return Arrays.asList(new Object[][]{
-                    {"countNotEqualsFourShouldLimitToFive", neq(4l), 5l},
-                    {"countLessThanOrEqualThreeShouldLimitToFour", lte(3l), 4l},
-                    {"countLessThanThreeShouldLimitToThree", lt(3l), 3l},
-                    {"countGreaterThanTwoShouldLimitToThree", gt(2l), 3l},
-                    {"countGreaterThanOrEqualTwoShouldLimitToTwo", gte(2l), 2l},
-                    {"countInsideTwoAndFourShouldLimitToFour", inside(2l, 4l), 4l},
-                    {"countOutsideTwoAndFourShouldLimitToFive", outside(2l, 4l), 5l},
-                    {"countWithinTwoSixFourShouldLimitToSeven", within(2l, 6l, 4l), 7l},
-                    {"countWithoutTwoSixFourShouldLimitToSix", without(2l, 6l, 4l), 6l}});
-        }
-
-        static Iterable<Object[]> generateNotTestParameters() {
-
-            return Arrays.asList(new Object[][]{
-                    {"countEqualsNullShouldUseNotStep", eq(0l)},
-                    {"countLessThanOneShouldUseNotStep", lt(1l)},
-                    {"countLessThanOrEqualNullShouldUseNotStep", lte(0l)}});
+            return Arrays.asList(new Traversal[][]{
+                    {__.out().count().is(0), __.not(__.out())},
+                    {__.out().count().is(lt(1)), __.not(__.out())},
+                    {__.out().count().is(lte(0)), __.not(__.out())},
+                    {__.out().count().is(neq(4)), __.out().limit(5).count().is(neq(4))},
+                    {__.out().count().is(lte(3)), __.out().limit(4).count().is(lte(3))},
+                    {__.out().count().is(lt(3)), __.out().limit(3).count().is(lt(3))},
+                    {__.out().count().is(gt(2)), __.out().limit(3).count().is(gt(2))},
+                    {__.out().count().is(gte(2)), __.out().limit(2).count().is(gte(2))},
+                    {__.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))}});
         }
     }
 }


[03/11] incubator-tinkerpop git commit: Fixed the previous commit. We don't want to increase the step offset, but decrease the traversal size, after removing steps from a traversal.

Posted by dk...@apache.org.
Fixed the previous commit. We don't want to increase the step offset, but decrease the traversal size, after removing steps from a traversal.


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

Branch: refs/heads/tp31
Commit: 041c0333b3ed4d765fcd4afa5d81666bcac0541d
Parents: bffa77f
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed May 25 21:55:27 2016 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Fri May 27 13:25:36 2016 +0200

----------------------------------------------------------------------
 .../traversal/strategy/optimization/RangeByIsCountStrategy.java  | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/041c0333/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 1b544c2..efa79e6 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
@@ -70,7 +70,7 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
 
     @Override
     public void apply(final Traversal.Admin<?, ?> traversal) {
-        final int size = traversal.getSteps().size();
+        int size = traversal.getSteps().size();
         Step prev = null;
         for (int i = 0; i < size; i++) {
             final Step curr = traversal.getSteps().get(i);
@@ -109,7 +109,7 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                         if (useNotStep) {
                             traversal.asAdmin().removeStep(next); // IsStep
                             traversal.asAdmin().removeStep(curr); // CountStep
-                            i += 2;
+                            size -= 2;
                             final Traversal.Admin inner = __.start().asAdmin();
                             TraversalHelper.insertAfterStep(prev, inner.getStartStep(), inner);
                             TraversalHelper.replaceStep(prev, new NotStep<>(traversal, inner), traversal);