Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixes #561: RELATE doesn't work as expected with map-parameters

  • Loading branch information...
commit e18e6ce5331b805dca5429b8af5a8fa3f31cc693 1 parent 14b66aa
@systay authored
View
17 cypher/src/main/scala/org/neo4j/cypher/internal/mutation/RelateLink.scala
@@ -27,14 +27,14 @@ import org.neo4j.graphdb._
import org.neo4j.cypher.internal.commands._
import org.neo4j.cypher.{RelatePathNotUnique, CypherTypeException}
-case class NamedExpectation(name : String, properties : Map[String,Expression]) {
- def this(name : String) = this(name, Map.empty)
- def compareWithExpectations(pc: PropertyContainer, ctx: ExecutionContext): Boolean = {
- properties.forall {
- case (k, exp) => {
- pc.hasProperty(k) && exp(ctx) == pc.getProperty(k)
- }
+case class NamedExpectation(name: String, properties: Map[String, Expression]) extends GraphElementPropertyFunctions {
+ def this(name: String) = this(name, Map.empty)
+
+ def compareWithExpectations(pc: PropertyContainer, ctx: ExecutionContext): Boolean = properties.forall {
+ case ("*", expression) => getMapFromExpression(expression(ctx)).forall {
+ case (k, value) => pc.hasProperty(k) && pc.getProperty(k) == value
}
+ case (k, exp) => pc.hasProperty(k) && exp(ctx) == pc.getProperty(k)
}
}
@@ -43,13 +43,12 @@ object RelateLink {
new RelateLink(NamedExpectation(start, Map.empty), NamedExpectation(end, Map.empty), NamedExpectation(relName, Map.empty), relType, dir)
}
-
case class RelateLink(start: NamedExpectation, end: NamedExpectation, rel: NamedExpectation, relType: String, dir: Direction)
extends GraphElementPropertyFunctions {
lazy val relationshipType = DynamicRelationshipType.withName(relType)
def exec(context: ExecutionContext, state: QueryState): RelateResult = {
- // We haven't yet figured out if we already have boths elements in the context
+ // We haven't yet figured out if we already have both elements in the context
// so let's start by finding that first
val s = getNode(context, start.name)
View
2  cypher/src/main/scala/org/neo4j/cypher/internal/mutation/UpdateAction.scala
@@ -49,7 +49,7 @@ trait GraphElementPropertyFunctions {
def rewrite(props: Map[String, Expression], f: (Expression) => Expression): Map[String, Expression] = props.map{ case (k,v) => k->v.rewrite(f) }
- private def getMapFromExpression(v: Any): Map[String, Any] = v match {
+ def getMapFromExpression(v: Any): Map[String, Any] = v match {
case m: collection.Map[String, Any] => m.toMap
case m: JavaMap[String, Any] => m.asScala.toMap
case x => throw new CypherTypeException("Don't know how to extract parameters from this type: " + x.getClass.getName)
View
16 cypher/src/test/scala/org/neo4j/cypher/MutatingIntegrationTests.scala
@@ -24,6 +24,7 @@ import org.junit.Assert._
import collection.JavaConverters._
import org.scalatest.Assertions
import org.neo4j.graphdb.{NotFoundException, Relationship, Node}
+import java.util.HashMap
class MutatingIntegrationTests extends ExecutionEngineHelper with Assertions with StatisticsChecker {
@@ -388,6 +389,21 @@ return distinct center""")
assertNull("Did not expect to be in a transaction now", graph.getTxManager.getTransaction)
}
+
+ @Test
+ def relate_twice_with_param_map() {
+ createNode()
+ createNode()
+
+ val map1 = Map("name" -> "Anders")
+ val map2 = new HashMap[String, Any]()
+ map2.put("name", "Anders")
+
+ val r1 = executeScalar[Relationship]("start a=node(1), b=node(2) relate a-[r:FOO {param}]->b return r", "param" -> map1)
+ val r2 = executeScalar[Relationship]("start a=node(1), b=node(2) relate a-[r:FOO {param}]->b return r", "param" -> map2)
+
+ assert(r1 === r2)
+ }
}
trait StatisticsChecker extends Assertions {
Please sign in to comment.
Something went wrong with that request. Please try again.