helmbert
helmbert

Reputation: 38004

"scala.MatchError" on Cypher CREATE query

I'm trying to insert a few nodes and edges into a Neo4j graph using Cypher statements. Upon executing the query, I get a not very meaningful scala.MatchError response from the server. I'm using Neo4j in version 2.2.0.

This is my Cypher query (note that it's originally part of a much larger query, but this is what I've narrowed it down to):

CREATE (node55549aefd9aa7:Arg {prop_node55549aefd9aa7})

Arguments for this query (in JSON notation):

{
  "prop_node55549aefd9aa7": {
    "startLine": 48,
    "endLine": 51,
    "type": 1,
    "byRef": false,
    "variadic": false,
    "name": "query",
    "default": null,
    "__node_id": "node55549aefd9aa7"
  }
}

This is the error response that I'm getting:

scala.MatchError: (default,null) (of class scala.Tuple2)  
    at org.neo4j.cypher.internal.compiler.v2_2.mutation.CreateNode$$anonfun$org$$$$c818f6fea869bbb25aedba7c5faae2d$$$$e$$fromAnyToLiteral$1$1.apply(CreateNode.scala:40)
    at org.neo4j.cypher.internal.compiler.v2_2.mutation.CreateNode$$anonfun$org$$$$c818f6fea869bbb25aedba7c5faae2d$$$$e$$fromAnyToLiteral$1$1.apply(CreateNode.scala:40)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at scala.collection.AbstractIterable.foreach(Iterable.scala:54)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:244)
    at scala.collection.AbstractTraversable.map(Traversable.scala:105)
// Several dozen lines of stack trace omitted

I'm using the everyman/neo4jphp library for accessing Neo4j from my PHP application. I suspect that's of little relevance, though, because the error is also reproducible when speaking directly to the REST API using a simple cURL call on the command line:

curl -D - \
    --user neo4j:XXXX \
    -H "content-type: application/json" \
    -d'{"statements":[{"statement":"CREATE (node55549aefd9aa7:Arg {prop_node55549aefd9aa7})", "parameters": {"prop_node55549aefd9aa7": {"startLine": 48, "endLine": 51, "type": 1, "byRef": false, "variadic": false, "name": "query", "default": null, "__node_id": "node55549aefd9aa7"}}}]}' \
    http://localhost:7474/db/data/transaction/commit

What does this error mean and why am I getting it?

Upvotes: 0

Views: 206

Answers (1)

helmbert
helmbert

Reputation: 38004

Turns out there is actually a bug report for current Neo4j versions for this issue that is discussed on GitHub. What scala.MatchError: (default,null) actually means is that the default property has a null value, which is apparently invalid in Neo4j.

In CREATE statements, node properties must not contain null values. From reading the GitHub issue, I'm not really sure if this is by design (and it's simply the error message that is unclear) or an actual bug. In any way, the query can be executed successfully by simply omitting the null properties from the query arguments:

{
  "prop_node55549aefd9aa7": {
    "startLine": 48,
    "endLine": 51,
    "type": 1,
    "byRef": false,
    "variadic": false,
    "name": "query",
    # "default": null,  <-- Remove the "default" property!
    "__node_id": "node55549aefd9aa7"
  }
}

Luckily, defining properties as null or not defining them at all is semantically equivalent in Neo4j. This means that query constraints like WHERE node.default IS NULL will still match nodes where the default property is not defined at all.

On the application side, a simple filter construct can be used to prevent null values from being used as properties:

$properties = array_filter($properties, function($value) {
    return $value !== NULL;
}

Upvotes: 1

Related Questions