Skip to content

Commit

Permalink
Bug: Keep traversal history when using RANGE (#196)
Browse files Browse the repository at this point in the history
Signed-off-by: Dwitry [email protected]
  • Loading branch information
dwitry authored Oct 12, 2018
1 parent 3fe8ab5 commit 68d6fcf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static java.util.Collections.emptyMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.groups.Tuple.tuple;

import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -99,6 +100,19 @@ public void threeExpressions() throws Exception {
.containsExactly(asList(2L, 4L));
}

@Test
public void keepTraversalHistory() throws Exception {
String cypher = "WITH ['a', 'b'] AS a UNWIND range(1, 2) as r RETURN r, a";
List<Map<String, Object>> results = submitAndGet(cypher);

assertThat(results)
.extracting("r", "a")
.containsExactly(
tuple(1L, asList("a", "b")),
tuple(2L, asList("a", "b"))
);
}

@Test
public void compileTimeValidations() throws Exception {
assertThatThrownBy(() -> submitAndGet("RETURN range(0, 10001) as r"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object CosmosDbFlavor extends GremlinRewriter {

private def rewriteRange(steps: Seq[GremlinStep]): Seq[GremlinStep] = {
replace({
case Repeat(SideEffect(aggregation) :: Nil) :: Until(untilTraversal) :: Cap(_) :: rest =>
case Repeat(SideEffect(aggregation) :: Nil) :: Until(untilTraversal) :: SelectK(_) :: rest =>
(aggregation, untilTraversal) match {
case (Loops :: Is(Gte(start: Long)) :: Aggregate(_) :: Nil, Loops :: Is(Gt(end: Long)) :: Nil) =>
val range = start until (end + 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ private class ExpressionWalker[T, P](context: WalkerContext[T, P], g: GremlinSte
)
)
.until(untilCondition)
.cap(rangeLabel)
.select(rangeLabel)
}

private def size(args: Seq[Expression]): GremlinSteps[T, P] = {
Expand Down

0 comments on commit 68d6fcf

Please sign in to comment.