【问题标题】:How to import a CSV file into Titan graph database?如何将 CSV 文件导入 Titan 图数据库?
【发布时间】:2013-10-01 03:29:09
【问题描述】:

谁能提供一些示例代码或提示,说明如何将 1MB CSV 节点和另一个 1MB CSV 边导入运行在 Cassandra 上的 Titan 图数据库?

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

我已经看到 Faunus 可以做到这一点,但如果可能的话,我想避免花费几天时间来设置它。

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

【问题讨论】:

    标签: database graph-databases titan gremlin tinkerpop


    【解决方案1】:

    https://groups.google.com/forum/#!topic/aureliusgraphs/ew9PJVxa8Xw 回答了我的问题:

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

    2) BatchGraph 代码 (Daniel Kuppitz)

    先决条件:

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

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

    【讨论】:

    猜你喜欢
    • 2021-11-22
    • 2021-10-20
    • 2012-10-24
    • 1970-01-01
    • 1970-01-01
    • 2016-12-30
    • 2018-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多