如何将CSV文件导入到Titan图数据库? [英] How to import a CSV file into Titan graph database?

查看:867
本文介绍了如何将CSV文件导入到Titan图数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以提供一些关于如何将1MB CSV节点和另一个1MB CSV边缘导入Cassandra上运行的Titan图表数据库的示例代码或提示?

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?

我有一个小的CSV文件导入通过Gremlin,但这似乎不适合大文件。

I've got small CSV files importing via Gremlin, but this doesn't seem appropriate for large files.

我看到Faunus可以做到这一点, d喜欢避免花费几天的时间设置它,如果可能的话。

I've seen Faunus can do this, but I'd like to avoid spending a couple of days setting it up if possible.

看起来BatchGraph可能是去的方式( https://github.com/tinkerpop/blueprints/wiki/Batch-Implementation ),但示例似乎不完整。

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.

推荐答案

我的问题已在 https://groups.google.com/forum/#!topic/aureliusgraphs/ew9PJVxa8Xw

1)gremlin脚本适用于1mb导入(Stephen Mallette)

1) The gremlin script is fine for a 1mb import (Stephen Mallette)

2)BatchGraph代码(Daniel Kuppitz)

2) BatchGraph code (Daniel Kuppitz)

先决条件:

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

在Gremlin REPL中:

In 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()

这篇关于如何将CSV文件导入到Titan图数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆