【问题标题】:Import Big CSV File Into Tarantool将大 CSV 文件导入 Tarantool
【发布时间】:2020-07-23 13:55:38
【问题描述】:

我正在寻找一种方法以最快的方式将大 CSV(数百万行和 20-30 个字段)插入到 tarantool db 中,最好是通过其中一个连接器(python 或 c#)并稍后在应用程序中访问空间用 python/c# 构建。

我是 tarantool 的新手,当我查看 tarantool 的文档时,我在这里找到了 CSV 内置模块 https://www.tarantool.io/en/doc/2.5/reference/reference_lua/csv/,但这实际上并没有在 tarantool 中创建空间。

然后我尝试创建空间,然后通过解析 csv 文件并将每条记录插入到空间中,通过 python 应用程序进行插入,如下所示

tester = connection.space('tester')
tester.insert((<data>))

但这在性能方面并不好,它非常慢。以更好的性能将 CSV 输入导入 tarantool 的最佳方法是什么?

谢谢。

【问题讨论】:

    标签: csv tarantool


    【解决方案1】:

    Tarantool csv 内置模块仅用于 csv 读取。是的,如果你想创造空间,你应该用手来做。

    我建议你尝试使用批量插入:

    -- You need to create stored lua procedure
    -- And of course it's only a draft of such function
    function batch_insert(list)
        box.begin()
            for _, record in ipairs(list) do
                space:replace(record)
            end
        box.commit()
    end
    

    然后就可以从python客户端调用这个过程了。

    connection.call('batch_insert', several_csv_rows)
    

    在 Tarantool 文档(例如 https://www.tarantool.io/en/doc/1.10/getting_started/getting_started_connectors/#executing-stored-procedures)中阅读有关 tarantool 存储过程的更多信息

    【讨论】:

    • 谢谢@Oleg 的回答,我会试一试的。
    猜你喜欢
    • 1970-01-01
    • 2015-10-15
    • 1970-01-01
    • 2012-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-08
    • 1970-01-01
    相关资源
    最近更新 更多