Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Predicates can now be returned and used to set properties

  • Loading branch information...
commit 9cac4f29c72036d2b86a0c13f39f904e7405956e 1 parent b38ad6f
@systay authored
View
4 cypher/CHANGES.txt
@@ -1,3 +1,7 @@
+1.9
+--------------------
+o Predicates can now be returned and used to set properties
+
1.8
--------------------
o Added escape characters to string literals
View
2  cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Expressions.scala
@@ -67,6 +67,8 @@ trait Expressions extends Base with ParserPattern with Predicates with StringLit
| parens(expression)
| failure("illegal value"))
+ def expressionOrPredicate: Parser[Expression] = pathExpression | predicate | expression
+
def numberLiteral: Parser[Expression] = number ^^ (x => {
val value: Any = if (x.contains("."))
x.toDouble
View
2  cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/ReturnClause.scala
@@ -30,7 +30,7 @@ trait ReturnClause extends Base with Expressions {
case col ~ None => col
} | "*" ^^^ AllIdentifiers()
- def returnItem: Parser[ReturnItem] = trap(expression) ^^ {
+ def returnItem: Parser[ReturnItem] = trap(expressionOrPredicate) ^^ {
case (expression, name) => ReturnItem(expression, name.replace("`", ""))
}
View
2  cypher/src/main/scala/org/neo4j/cypher/internal/parser/v1_9/Updates.scala
@@ -48,7 +48,7 @@ trait Updates extends Base with Expressions with StartClause {
def set: Parser[(Seq[UpdateAction], Seq[NamedPath])] = ignoreCase("set") ~> commaList(propertySet) ^^ ((_,Seq()))
- def propertySet = property ~ "=" ~ expression ^^ {
+ def propertySet = property ~ "=" ~ expressionOrPredicate ^^ {
case p ~ "=" ~ e => PropertySetAction(p.asInstanceOf[Property], e)
}
}
View
15 cypher/src/test/scala/org/neo4j/cypher/CypherParserTest.scala
@@ -1775,6 +1775,17 @@ foreach(x in [1,2,3] :
returns(ReturnItem(Identifier("p"), "p")))
}
+
+ @Test def use_predicate_as_expression() {
+ testFrom_1_9("start n=node(0) return id(n) = 0, n is null",
+ Query.
+ start(NodeById("n", 0)).
+ returns(
+ ReturnItem(Equals(IdFunction(Identifier("n")), Literal(0)), "id(n) = 0"),
+ ReturnItem(IsNull(Identifier("n")), "n is null")
+ ))
+ }
+
def test_1_9(query: String, expectedQuery: Query) {
testQuery(None, query, expectedQuery)
testQuery(None, query + ";", expectedQuery)
@@ -1794,6 +1805,10 @@ foreach(x in [1,2,3] :
test_1_9(query, expectedQuery)
}
+ def testFrom_1_9(query: String, expectedQuery: Query) {
+ test_1_9(query, expectedQuery)
+ }
+
def testAll(query: String, expectedQuery: Query) {
test_1_7(query, expectedQuery)
test_1_8(query, expectedQuery)
View
5 cypher/src/test/scala/org/neo4j/cypher/ExecutionEngineTest.scala
@@ -2184,5 +2184,10 @@ RETURN x0.name?
assert(result.endNode() === a)
}
+ @Test
+ def should_be_able_to_return_predicate_result() {
+ val result = parseAndExecute("START a=node(0) return id(a) = 0, a is null").toList
+ assert(result === List(Map("id(a) = 0" -> true, "a is null" -> false)))
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.