提交 ebb387b8 编写于 作者: A Andres Taylor

Fixes #1876 - Null nodes and properties should be ignored when SETting properties

上级 67986996
......@@ -22,7 +22,6 @@ package org.neo4j.cypher.internal.compiler.v2_0.mutation
import org.neo4j.cypher.internal.compiler.v2_0._
import commands.expressions._
import pipes.QueryState
import symbols._
import org.neo4j.graphdb.{Relationship, Node}
import org.neo4j.helpers.ThisShouldNotHappenError
......@@ -34,23 +33,23 @@ case class PropertySetAction(prop: Property, e: Expression)
def exec(context: ExecutionContext, state: QueryState) = {
implicit val s = state
val value = makeValueNeoSafe(e(context))
val qtx = state.query
mapExpr(context) match {
case (n: Node) =>
if ( null == value )
propertyKey.getOptId(qtx).foreach(qtx.nodeOps.removeProperty(n.getId, _))
else
qtx.nodeOps.setProperty(n.getId, propertyKey.getOrCreateId(qtx), value)
case (r: Relationship) =>
if ( null == value )
propertyKey.getOptId(qtx).foreach(qtx.relationshipOps.removeProperty(r.getId, _))
else
qtx.relationshipOps.setProperty(r.getId, propertyKey.getOrCreateId(qtx), value)
case _ =>
throw new ThisShouldNotHappenError("Stefan", "This should be a node or a relationship")
val expr = mapExpr(context)
if (expr != null) {
val (id, ops) = expr match {
case (e: Relationship) => (e.getId, qtx.relationshipOps)
case (e: Node) => (e.getId, qtx.nodeOps)
case _ => throw new ThisShouldNotHappenError("Stefan", "This should be a node or a relationship")
}
makeValueNeoSafe(e(context)) match {
case null => propertyKey.getOptId(qtx).foreach(ops.removeProperty(id, _))
case value => ops.setProperty(id, propertyKey.getOrCreateId(qtx), value)
}
}
Iterator(context)
}
......
......@@ -4,6 +4,7 @@ o Fixes bug around MERGE inside a FOREACH inside a FOREACH
o Makes it possible to write MERGE queries with no already known parts
o Fixes problem with compiling queries with NOT expressions in them
o Fixes #1735 - Indexes and AND predicates produce wrong results
o Fixes #1876 - Null nodes and properties should be ignored when SETting properties
2.0.0-RC1
---------
......
package org.neo4j.cypher
import org.junit.Test
class NullAcceptanceTest extends ExecutionEngineHelper {
@Test def null_nodes_should_be_silently_ignored() {
// Given empty database
// When
val result = execute("optional match (a:DoesNotExist) set a.prop = 42 return a")
// Then doesn't throw
result.toList
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册