1
votes

I have a neo4j graph (created using gremlin), and I'd like to use it using Gremlin as well, however, cypher queries on the graph do not seem to work:

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)
}

This is how I try to execute the query:

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] = []

If I load the graph into Neo4j server, the same query works on the neo4j web console.

match (n) return n limit 10

neo4j output

I'm using the following libs:

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
How do you go about querying Neo with Gremlin? Any tuts or libraries you can recommend?swelet
If you already have a neo graph, e.g. in val location = "~/bin/neo4j-community-3.0.4/data/databases/graph.db", you can load it directly into gremlin using Neo4jGraph.open(location), open a traversal val t = graph.traversal() and then do gremlin queries val res = t.V().blah().blah() Read this for the gremlin traversal queries -> tinkerpop.apache.org/docs/current/reference/#traversalixaxaar
Also, you can use cypher in gremlin using graph.cypher("match your cypher-query") Refer the code above (in scala) in case you need some boilerplate. The sbt dependencies are listed above as wellixaxaar

1 Answers

0
votes

Very sorry for this, turns out I was opening a new graph (fileName was incorrect).

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]}]