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 2015/05/19 22:39:54 UTC

incubator-tinkerpop git commit: fixed RangeByIsCountStrategy

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 16d7e5efc -> fe8b28f18


fixed 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/fe8b28f1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/fe8b28f1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/fe8b28f1

Branch: refs/heads/master
Commit: fe8b28f18894db1064b9fd6f73fd21f05125846a
Parents: 16d7e5e
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Tue May 19 22:39:40 2015 +0200
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Tue May 19 22:39:40 2015 +0200

----------------------------------------------------------------------
 .../strategy/optimization/RangeByIsCountStrategy.java    | 11 ++++++++---
 .../optimization/RangeByIsCountStrategyTest.java         |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fe8b28f1/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 157acb3..5bbc224 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,6 +25,8 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.filter.IsStep;
 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.ConjunctionP;
+import org.apache.tinkerpop.gremlin.process.traversal.util.OrP;
 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;
@@ -76,21 +78,24 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
                 final Step next = traversal.getSteps().get(i + 1);
                 if (next instanceof IsStep && !(prev instanceof RangeGlobalStep)) { // if a RangeStep was provided, assume that the user knows what he's doing
                     final IsStep isStep = (IsStep) next;
+                    final P isStepPredicate = isStep.getPredicate();
                     Long highRange = null;
-                    for (P p : isStep.getPredicate() instanceof AndP ? ((AndP<?>) isStep.getPredicate()).getPredicates() : Collections.singletonList(isStep.getPredicate())) {
+                    for (P p : isStepPredicate instanceof ConjunctionP ? ((ConjunctionP<?>) isStepPredicate).getPredicates() : Collections.singletonList(isStepPredicate)) {
                         final Object value = p.getValue();
                         final BiPredicate predicate = p.getBiPredicate();
                         if (value instanceof Number) {
                             final long highRangeOffset = INCREASED_OFFSET_SCALAR_PREDICATES.contains(predicate) ? 1L : 0L;
                             final Long highRangeCandidate = ((Number) value).longValue() + highRangeOffset;
-                            highRange = highRange == null || highRangeCandidate > highRange ? highRangeCandidate : highRange;
+                            final boolean update = highRange == null || highRangeCandidate > highRange;
+                            if (update) highRange = highRangeCandidate;
                         } else {
                             final Long highRangeOffset = RANGE_PREDICATES.get(predicate);
                             if (value instanceof Collection && highRangeOffset != null) {
                                 final Object high = Collections.max((Collection) value);
                                 if (high instanceof Number) {
                                     final Long highRangeCandidate = ((Number) high).longValue() + highRangeOffset;
-                                    highRange = highRange == null || highRangeCandidate > highRange ? highRangeCandidate : highRange;
+                                    final boolean update = highRange == null || highRangeCandidate > highRange;
+                                    if (update) highRange = highRangeCandidate;
                                 }
                             }
                         }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/fe8b28f1/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 d5da778..5e2200e 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
@@ -172,7 +172,7 @@ public class RangeByIsCountStrategyTest {
                     {"countGreaterThanTwoShouldLimitToThree", gt(2l), 3l},
                     {"countGreaterThanOrEqualTwoShouldLimitToTwo", gte(2l), 2l},
                     {"countInsideTwoAndFourShouldLimitToFour", inside(2l, 4l), 4l},
-                    //{"countOutsideTwoAndFourShouldLimitToFive", outside(2l, 5l), 5l}, // TODO: RangeByIsCountStrategy currently doesn't optimize OrP
+                    {"countOutsideTwoAndFourShouldLimitToFive", outside(2l, 4l), 5l},
                     {"countWithinTwoSixFourShouldLimitToSeven", within(2l, 6l, 4l), 7l},
                     {"countWithoutTwoSixFourShouldLimitToSix", without(2l, 6l, 4l), 6l}});
         }