Creating graph in titan from data in csv - example wiki.Vote gives error

343 views Asked by At

I am new to Titan - I loaded titan and successfully ran GraphOfTheGods example including queries given. Next I went on to try bulk loading csv file to create graph and followed steps in Powers of ten - Part 1 http://thinkaurelius.com/2014/05/29/powers-of-ten-part-i/

I am getting an error in loading wiki-Vote.txt

gremlin> g = TitanFactory.open("/tmp/1m") Backend shorthand unknown: /tmp/1m 

I tried:

g = TitanFactory.open('conf/titan-berkeleydb-es.properties’)

but get an error in the next step in load-1m.groovy

==>titangraph[berkeleyje:/titan-0.5.4-hadoop2/conf/../db/berkeley] No signature of method: groovy.lang.MissingMethodException.makeKey() is applicable for argument types: () values: [] Possible solutions: every(), any()

Any hints what to do next? I am using groovy for the first time. what kind of groovy expertise needed for working with gremlin

2

There are 2 answers

2
stephen mallette On

That blog post is meant for Titan 0.4.x. The API shifted when Titan went to 0.5.x. The same principles discussed in the posts generally apply to data loading but the syntax is different in places. The intention is to update those posts in some form when Titan 1.0 comes out with full support of TinkerPop3. Until then, you will need to convert those code examples to the revised API.

For example, an easy way to create a berkeleydb database is with:

g = TitanFactory.build()
    .set("storage.backend", "berkeleyje")
    .set("storage.directory", "/tmp/1m")
    .open();

Please see the docs here. Then most of the schema creation code (which is the biggest change) is now described here and here.

0
accidental_PhD On

After much experimenting today, I finally figured it out. A lot of changes were needed:

  • Use makePropertyKey() instead of makeKey(), and makeEdgeLabel() instead of makeLabel()
  • Use cardinality(Cardinality.SINGLE) instead of unique()
  • Building the index is quite a bit more complicated. Use the management system instead of the graph both to make the keys and labels, as well as build the index (see https://groups.google.com/forum/#!topic/aureliusgraphs/lGA3Ye4RI5E)

For posterity, here's the modified script that should work (as of 0.5.4):

g = TitanFactory.build().set("storage.backend", "berkeleyje").set("storage.directory", "/tmp/1m").open()

m = g.getManagementSystem()
k = m.makePropertyKey('userId').dataType(String.class).cardinality(Cardinality.SINGLE).make()
m.buildIndex('byId', Vertex.class).addKey(k).buildCompositeIndex()
m.makeEdgeLabel('votesFor').make()
m.commit()

getOrCreate = { id ->
  def p = g.V('userId', id)
    if (p.hasNext()) {
        p.next()
    } else {
        g.addVertex([userId:id])
    }
}

new File('wiki-Vote.txt').eachLine {
  if (!it.startsWith("#")){
    (fromVertex, toVertex) = it.split('\t').collect(getOrCreate)
    fromVertex.addEdge('votesFor', toVertex)
  }
}

g.commit()