【问题标题】:Can I import a csv into a collection and link it to another collection at one go in ArangoDB?我可以将 csv 导入一个集合,然后在 ArangoDB 中一次将其链接到另一个集合吗?
【发布时间】:2019-04-02 18:23:52
【问题描述】:

我有 2 个 CSV 文件,它们是关系数据库的导出文件。
CSV1 具有唯一 ID,
CSV2 没有,但有一个链接到 CSV1 对象的列。
我导入 CSV1,将唯一 ID 映射到 _key。
我想将 CSV2 导入另一个集合,并通过边缘将其链接到第一个集合中的对象。
最简单的方法是什么?

附言
(我知道在 Neo4j 中,使用导入工具这样的事情是微不足道的,我想知道 ArangoDB 中是否存在这样的功能,或者我必须编写一些 AQL 来做到这一点。

真诚地, 埃拉德

【问题讨论】:

    标签: csv arangodb


    【解决方案1】:

    虽然没有导入数据的向导,但假设您熟悉命令行(因为您在此站点,我敢打赌),将数据导入 ArangoDB 也很简单:

    1. 使用 Arango 导入工具将您的 CSV 文件导入到两个集合中
    2. 创建您的边缘集合
    3. 使用简单的 AQL 查询将数据插入到边缘集合中

    以下是使用 arangoimp 导入 csv 的示例语法:

    arangoimp --file <path/filename> --collection <collectionName> --create-collection true --type csv --server.database <databaseName> —server.username <username>
    

    以下是一些常用选项:

    翻译列名:

    arangoimport --file "data.csv" --type csv --translate "from=_from" --translate "to=_to"
    

    忽略空值(而不是抛出警告并且不加载数据),使用标志:

    --ignore-missing
    

    忽略导入文件中的列:

    arangoimport --file "data.csv" --type csv --remove-attribute “attributeName”
    

    此外,如果您在 csv 文件中已有边缘集合,您也可以直接导入:

    arangoimp --file <path/filename> --collection <collectionName> --create-collection true --type csv --create-collection-type edge --server.database <databaseName>
    

    最后,请注意上面列表中的 2 和 3 可以在 Arango GUI 中完成,如果您觉得那里更舒服的话。 3 的语句可能类似于

    let newEdges = ( for csv1rec in csv1_collection
                      for csv2rec in csv2_collection
                      filter csv1rec.id = csv2rec.colA
                    return {from : csv1rec.id , to : csv2rec.colA} )
    for rec in newEdges
    insert {_from: rec.from, _to: rec.to} in edgeCollection
    

    请注意,我是从内存中为第 3 步编写上面的 AQL,因此可能需要稍作调整。

    【讨论】:

    • 我的查询完全不同,在哪里可以找到 arangoimport 工具,如何在 Windows 系统上下载?
    • @AnshumanSrivastava arangoimport 与常规 arangodb 安装一起安装(以及其他工具 -arangodb.com/docs/stable/programs.html-)。我正在运行 docker 映像,它们都安装在 /usr/bin 中。虽然我没有 Windows 机器,但文档说默认情况下数据库安装在 C;\Users\AppData\local 或 c:\program Files\ArangoDB-3.x.x (arangodb.com/docs/stable/installation-windows.html)跨度>
    • 感谢@camba1 找到了路径
    猜你喜欢
    • 2012-08-06
    • 2021-07-10
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 2015-09-14
    • 1970-01-01
    • 2017-07-18
    • 1970-01-01
    相关资源
    最近更新 更多