AnormCypher 文档提供了一个如何使用 Stream API 检索数据的示例:http: //anormcypher.org/
“访问返回查询结果的第一种方法是使用 Stream API。
当您在任何 Cypher 语句上调用 apply() 时,您将收到一个 CypherRow 实例的惰性流,其中每一行都可以视为一个字典:
// Create Cypher query
val allCountries = Cypher("start n=node(*) where n.type = 'Country' return n.code as code, n.name as name")
// Transform the resulting Stream[CypherRow] to a List[(String,String)]
val countries = allCountries.apply().map(row =>
row[String]("code") -> row[String]("name")
).toList
我正在尝试使用相同的方法通过以下 Cypher 查询获取路径:
MATCH p = (n {id: 'n5'})-[*]-(m) RETURN p;
然而,在运行此代码时:
Cypher("MATCH p = (n {id: 'n5'})-[*]-(m) RETURN p;")().map {row =>
println(row[Option[org.anormcypher.NeoRelationship]]("p"))
}
我得到异常(见下文)。CypherRow
在这种情况下如何获取路径信息?
Exception in thread "main" java.lang.RuntimeException: TypeDoesNotMatch(Unexpected type while building a relationship)
at org.anormcypher.MayErr$$anonfun$get$1.apply(Utils.scala:21)
at org.anormcypher.MayErr$$anonfun$get$1.apply(Utils.scala:21)
at scala.util.Either.fold(Either.scala:97)
at org.anormcypher.MayErr.get(Utils.scala:21)
at org.anormcypher.CypherRow$class.apply(AnormCypher.scala:303)
at org.anormcypher.CypherResultRow.apply(AnormCypher.scala:309)
at bigdata.test.n4j.Simple$$anonfun$main$1.apply(Simple.scala:31)
at bigdata.test.n4j.Simple$$anonfun$main$1.apply(Simple.scala:29)
at scala.collection.immutable.Stream.map(Stream.scala:376)
at bigdata.test.n4j.Simple$.main(Simple.scala:29)