Tinkerpop Neo4j cypher查询无效

时间:2016-08-14 10:08:41

标签: neo4j gremlin tinkerpop tinkerpop3

我有一个neo4j图(使用gremlin创建),我也想使用Gremlin,但是,图上的cypher查询似乎不起作用:

import org.apache.tinkerpop.gremlin
import gremlin.neo4j.structure.Neo4jGraph
import gremlin.tinkergraph.structure.TinkerGraph
import gremlin.hadoop.structure.HadoopGraph
import org.apache.commons.configuration.Configuration

trait Graph[G] {
  def create(location: String, args: Configuration = null): G
}

object Grapher {

  implicit val createNeo4j = new Graph[Neo4jGraph] {
    def create(location: String, args: Configuration = null) =
      if (args != null) Neo4jGraph.open(args) else Neo4jGraph.open(location)
  }

  implicit val createTinkerGraph = new Graph[TinkerGraph] {
    def create(location: String, args: Configuration = null) =
      if (args != null) TinkerGraph.open(args) else TinkerGraph.open()
  }

  implicit val createHadoopGraph = new Graph[HadoopGraph] {
    def create(location: String, args: Configuration = null) =
      if (args != null) HadoopGraph.open(args) else HadoopGraph.open(location)
  }
}

object GraphSyntax {
  def createGraph[G](location: String, args: Configuration = null)(implicit graph: Graph[G]) = graph.create(location, args)
}

这是我尝试执行查询的方式:

import Grapher._
import GraphSyntax._

val graph = createGraph[Neo4jGraph](fileName)
// org.apache.tinkerpop.gremlin.neo4j.structure.Neo4jGraph = neo4jgraph[community single [/media/ixaxaar/Source/src/telperion/core/neo4j.db]]

graph.cypher("match (n) return n limit 10").toList
// java.util.List[Nothing] = []

如果我将图形加载到Neo4j服务器中,同样的查询将在neo4j Web控制台上运行。

match (n) return n limit 10

neo4j output

我正在使用以下库:

final val Gremlin                  = "3.2.1"
final val Neo4jTinkerpop           = "0.4-3.0.3"
val gremlinCore        = "org.apache.tinkerpop"   % "gremlin-core"             % Version.Gremlin
val gremlinGiraph      = "org.apache.tinkerpop"   % "giraph-gremlin"           % Version.Gremlin
val gremlinNeo4j       = "org.apache.tinkerpop"   % "neo4j-gremlin"            % Version.Gremlin
val hadoopGremlin      = "org.apache.tinkerpop"   % "hadoop-gremlin"           % Version.Gremlin
val tinkergraphGremlin = "org.apache.tinkerpop"   % "tinkergraph-gremlin"      % Version.Gremlin
val neo4jTinkerpop     = "org.neo4j"              % "neo4j-tinkerpop-api-impl" % Version.Neo4jTinkerpop

1 个答案:

答案 0 :(得分:0)

非常抱歉,事实证明我正在打开一个新图表(fileName不正确)。

scala> graph.cypher("match (n) return n limit 10").toList
res3: java.util.List[Nothing] = [{n=v[0]}, {n=v[1]}, {n=v[2]}, {n=v[3]}, {n=v[4]}, {n=v[5]}, {n=v[6]}, {n=v[7]}, {n=v[8]}, {n=v[9]}]