【问题标题】:"scala.MatchError" on Cypher CREATE queryCypher CREATE 查询中的“scala.MatchError”
【发布时间】:2015-05-14 13:22:32
【问题描述】:

我正在尝试使用 Cypher 语句 将一些节点和边插入到 Neo4j 图中。执行查询后,我从服务器收到了一个不太有意义的scala.MatchError 响应。我在 版本 2.2.0 中使用 Neo4j。

这是我的 Cypher 查询(请注意,它最初是一个 更大的查询的一部分,但这是我缩小的范围):

CREATE (node55549aefd9aa7:Arg {prop_node55549aefd9aa7})

此查询的参数(JSON 表示法):

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

这是我得到的错误响应:

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

我正在使用everyman/neo4jphp 库从我的 PHP 应用程序访问 Neo4j。不过,我怀疑这无关紧要,因为在命令行上使用简单的 cURL 调用直接与 REST API 对话时,该错误也是可重现的:

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

这个错误是什么意思,为什么我会得到它?

【问题讨论】:

    标签: php neo4j cypher


    【解决方案1】:

    事实证明,当前 Neo4j 版本实际上有一个 错误报告,用于解决此问题,即 discussed on GitHubscala.MatchError: (default,null) 实际上的意思default 属性有一个 null 值,这在 Neo4j 中显然是无效的。

    CREATE 语句中,节点属性不得包含null 值。通过阅读 GitHub 问题,我不确定这是设计使然(只是错误消息不清楚)还是实际错误。无论如何,只要从查询参数中省略null 属性,查询就可以成功执行:

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

    幸运的是,将属性定义为 null 或根本不定义它们在 Neo4j 中是语义等效。这意味着像 WHERE node.default IS NULL 这样的查询约束仍然会匹配根本没有定义 default 属性的节点。

    在应用程序端,可以使用简单的过滤器构造来防止 null 值被用作属性:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-12
      • 2014-05-24
      • 2018-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多