V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
zoain
V2EX  ›  分享创造

一个支持 Lua 的高性能数据迁移工具

  •  1
     
  •   zoain · 2022-03-03 13:24:08 +08:00 via iPhone · 1869 次点击
    这是一个创建于 784 天前的主题,其中的信息可能已经有所发展或是发生改变。

    river - 高性能数据迁移工具

    Github: https://github.com/cc-morning/river

    不吝给个 star !

    特性

    • 高性能,基于流的形式迁移数据
    • 支持多种文件以及多种数据库之间互相迁移
    • 支持 Lua (兼容 jit 及协程,并且支持 ffi )脚本实现高自定义性操作

    使用教程

    整个迁移流程就像一条河流

        // 直接迁移
        From Stream -> To Stream
         |              |
     e.g: Oracle    e.g: PostgreSQL
    
                        Lua 脚本
        // Lua 脚本迁移   /
        From Stream -> Filter Stream -> To Stream
         |                               |
     e.g: Oracle | JSON | CSV        e.g: MySQL | ES | PostgreSQL
    

    支持的类型

    From:CSV ,JSON ,MySQL ,Oracle ,PostgreSQL

    To:Elasticsearch ,MySQL ,Oracle ,PostgreSQL

    示例

    config.toml

    [task1]
    thread = 2 # 任务协程运行时的调度线程数
    filter = "type_conver.lua" # Lua 脚本
    
    [task1.from.csv]
    path = [ "/xxx/xxx/test1.csv", "/xxx/xxx/test2.csv" ]
    delimiter = "," # 分隔符
    flexible = true # 忽略错位
    quoting = true # 支持引号
    double_quote = true # 引号转义
    
    [task1.to.postgresql]
    url = "postgresql://test:[email protected]/test"
    table = "test"
    fixnul = true # 修复 0x00
    
    [task2.from.json]
    path = [ "/xxx/xxx/test1.json", "/xxx/xxx/test2.json" ]
    columns = "id,name,sex,age"
    parallel = 10240 # 格式化,提取指定 key 行为并行度
    
    [task2.to.mysql]
    url = "mysql://test:[email protected]/test"
    table = "test"
    

    多个任务会多线程同时执行。

    运行命令

    # // 不打印日志执行
    # river config.toml
    # 
    # // 打印日志执行(日志级别:error ,warn ,info ,debug ,trace )
    # LOG=info river config.toml
    
    3 条回复    2022-03-04 11:34:40 +08:00
    zoain
        1
    zoain  
    OP
       2022-03-03 13:29:14 +08:00
    得益于 lua 的灵活以及 jit 提供不俗的性能,甚至可以拿来做一些简单的清洗工作😃
    pkwenda
        2
    pkwenda  
       2022-03-03 15:12:52 +08:00
    lua 库必须 star
    zoain
        3
    zoain  
    OP
       2022-03-04 11:34:40 +08:00
    @pkwenda 哈哈哈,lua 确实不错😌
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3477 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 11:17 · PVG 19:17 · LAX 04:17 · JFK 07:17
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.