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 2017/09/26 17:28:20 UTC
[38/39] tinkerpop git commit: Fixed a bug in `RangeByIsCountStrategy`
that led to unexpected behaviors when predicates were used with floating
point numbers.
Fixed a bug in `RangeByIsCountStrategy` that led to unexpected behaviors when predicates were used with floating point numbers.
Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/568ba084
Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/568ba084
Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/568ba084
Branch: refs/heads/TINKERPOP-1782
Commit: 568ba08419774d990069bdc3be674bddf32ec4d5
Parents: 40f93dd
Author: Daniel Kuppitz <da...@hotmail.com>
Authored: Wed Sep 13 14:08:07 2017 -0700
Committer: Daniel Kuppitz <da...@hotmail.com>
Committed: Tue Sep 26 10:20:37 2017 -0700
----------------------------------------------------------------------
.../strategy/optimization/RangeByIsCountStrategy.java | 10 +++++++++-
.../strategy/optimization/RangeByIsCountStrategyTest.java | 3 +++
2 files changed, 12 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/568ba084/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 85e5753..2c55093 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
@@ -31,6 +31,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.filter.*;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.CountGlobalStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.GraphStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep;
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;
@@ -94,7 +95,7 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
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;
+ final Long highRangeCandidate = (long) Math.ceil(((Number) value).doubleValue()) + highRangeOffset;
final boolean update = highRange == null || highRangeCandidate > highRange;
if (update) {
if (parent instanceof EmptyStep) {
@@ -164,6 +165,13 @@ public final class RangeByIsCountStrategy extends AbstractTraversalStrategy<Trav
else
traversal.asAdmin().addStep(new NotStep<>(traversal, inner));
}
+ } else if (size == 0) {
+ final Step parentStep = traversal.getParent().asStep();
+ if (!(parentStep instanceof EmptyStep)) {
+ final Traversal.Admin parentTraversal = parentStep.getTraversal();
+ //parentTraversal.removeStep(parentStep); // this leads to IndexOutOfBoundsExceptions
+ TraversalHelper.replaceStep(parentStep, new IdentityStep<>(parentTraversal), parentTraversal);
+ }
}
} else {
TraversalHelper.insertBeforeStep(new RangeGlobalStep<>(traversal, 0L, highRange), curr, traversal);
http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/568ba084/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 8767989..856420f 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
@@ -99,6 +99,9 @@ public class RangeByIsCountStrategyTest {
{__.and(__.out().count().is(0), __.in().count().is(1)), __.and(__.not(__.out()), __.in().limit(2).count().is(1))},
{__.and(__.out().count().is(1), __.in().count().is(0)), __.and(__.out().limit(2).count().is(1), __.not(__.in()))},
{__.or(__.out().count().is(0), __.in().count().is(0)), __.or(__.not(__.out()), __.not(__.in()))},
+ {__.path().filter(__.count().is(gte(0.5))).limit(5), __.path().identity().limit(5)}, // unfortunately we can't just remove the filter step
+ {__.path().filter(__.unfold().count().is(gte(0.5))), __.path().filter(__.unfold())},
+ {__.path().filter(__.unfold().count().is(gte(1.5))), __.path().filter(__.unfold().limit(2).count().is(gte(1.5)))},
});
}