Skip to content

Commit

Permalink
Merge pull request #8015 from Mats-SX/3.0-list-slice-in
Browse files Browse the repository at this point in the history
Make `IN` work with list slices and subscripts
  • Loading branch information
jexp committed Sep 24, 2016
2 parents f3746e7 + 4cee00a commit fa26a7d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Expand Up @@ -25,6 +25,42 @@ import scala.collection.JavaConverters._

class ExpressionAcceptanceTest extends ExecutionEngineFunSuite with QueryStatisticsTestSupport with NewPlannerTestSupport {

test("IN should work with nested list subscripting") {
val query = """WITH [[1, 2, 3]] AS list
|RETURN 3 IN list[0] AS r
""".stripMargin

val result = executeWithAllPlanners(query)

result.toList should equal(List(Map("r" -> true)))
}

test("IN should work with nested literal list subscripting") {
val query = "RETURN 3 IN [[1, 2, 3]][0] AS r"

val result = executeWithAllPlanners(query)

result.toList should equal(List(Map("r" -> true)))
}

test("IN should work with list slices") {
val query = """WITH [1, 2, 3] AS list
|RETURN 3 IN list[0..1] AS r
""".stripMargin

val result = executeWithAllPlanners(query)

result.toList should equal(List(Map("r" -> false)))
}

test("IN should work with literal list slices") {
val query = "RETURN 3 IN [1, 2, 3][0..1] AS r"

val result = executeWithAllPlanners(query)

result.toList should equal(List(Map("r" -> false)))
}

test("accepts property access on type Any") {
val query = "WITH [{prop: 1}, 1] AS list RETURN (list[0]).prop AS p"

Expand Down
Expand Up @@ -127,9 +127,7 @@ trait Expressions extends Parser

private def Expression3: Rule1[ast.Expression] = rule("an expression") {
Expression2 ~ zeroOrMore(WS ~ (
"[" ~~ Expression ~~ "]" ~~>> (ast.ContainerIndex(_: ast.Expression, _))
| "[" ~~ optional(Expression) ~~ ".." ~~ optional(Expression) ~~ "]" ~~>> (ast.ListSlice(_: ast.Expression, _, _))
| group(operator("=~") ~~ Expression2) ~~>> (ast.RegexMatch(_: ast.Expression, _))
group(operator("=~") ~~ Expression2) ~~>> (ast.RegexMatch(_: ast.Expression, _))
| group(keyword("IN") ~~ Expression2) ~~>> (ast.In(_: ast.Expression, _))
| group(keyword("STARTS WITH") ~~ Expression2) ~~>> (ast.StartsWith(_: ast.Expression, _))
| group(keyword("ENDS WITH") ~~ Expression2) ~~>> (ast.EndsWith(_: ast.Expression, _))
Expand All @@ -143,6 +141,8 @@ trait Expressions extends Parser
Expression1 ~ zeroOrMore(WS ~ (
PropertyLookup
| NodeLabels ~~>> (ast.HasLabels(_: ast.Expression, _))
| "[" ~~ Expression ~~ "]" ~~>> (ast.ContainerIndex(_: ast.Expression, _))
| "[" ~~ optional(Expression) ~~ ".." ~~ optional(Expression) ~~ "]" ~~>> (ast.ListSlice(_: ast.Expression, _, _))
))
}

Expand Down

0 comments on commit fa26a7d

Please sign in to comment.