简体   繁体   English

如何将CSV文件导入Titan图数据库?

[英]How to import a CSV file into Titan graph database?

Can anyone supply some sample code or hints on how to import a 1MB CSV of nodes, and another 1MB CSV of edges, into Titan graph database running on Cassandra? 任何人都可以提供一些示例代码或提示,如何将1MB CSV节点和另外1MB CSV边缘导入到Cassandra上运行的Titan图数据库中?

I've got small CSV files importing via Gremlin, but this doesn't seem appropriate for large files. 我有通过Gremlin导入的小型CSV文件,但这似乎不适合大文件。

I've seen Faunus can do this, but I'd like to avoid spending a couple of days setting it up if possible. 我见过Faunus可以做到这一点,但是如果可能的话,我想避免花几天的时间来设置它。

It looks like BatchGraph might be the way to go ( https://github.com/tinkerpop/blueprints/wiki/Batch-Implementation ) but the example appears to be incomplete. 看起来BatchGraph可能是最好的方法( https://github.com/tinkerpop/blueprints/wiki/Batch-Implementation ),但示例似乎不完整。

My question was answered at https://groups.google.com/forum/#!topic/aureliusgraphs/ew9PJVxa8Xw : 我的问题已在https://groups.google.com/forum/#!topic/aureliusgraphs/ew9PJVxa8Xw上得到解答:

1) The gremlin script is fine for a 1mb import (Stephen Mallette) 1)gremlin脚本适用于1mb导入(Stephen Mallette)

2) BatchGraph code (Daniel Kuppitz) 2)BatchGraph代码(Daniel Kuppitz)

Prerequisties: Prerequisties:

echo "alice,32"         > /tmp/vertices.csv
echo "bob,33"          >> /tmp/vertices.csv
echo "alice,knows,bob"  > /tmp/edges.csv

In Gremlin REPL: 在Gremlin REPL中:

config = new BaseConfiguration()
config.setProperty("storage.backend", "inmemory")

g = TitanFactory.open(config)
bg = new BatchGraph(g, VertexIDType.STRING, 1000)

new File("/tmp/vertices.csv").each({ line ->
  (username, age) = line.split(",")
  user = bg.addVertex("user::" + username)
  ElementHelper.setProperties(user, ["username":username,"age":age.toInteger()])
})

new File("/tmp/edges.csv").each({ line ->
  (source, label, target) = line.split(",")

  v1 = bg.getVertex("user::" + source)
  v2 = bg.getVertex("user::" + target)

  bg.addEdge(null, v1, v2, label)
})

bg.commit()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM