【问题标题】:How to write into an Apache Arrow feather file in C++?如何在 C++ 中写入 Apache Arrow 羽毛文件?
【发布时间】:2020-11-13 21:15:40
【问题描述】:

将数据写入 Apache Arrow 支持的 Feather format 的 C++ 代码的最小示例是什么?该文件稍后将用于从 Python 代码中进行映射读取。

假设我们有一个arrow::Table的实例,如何将其内容写入羽毛文件?

【问题讨论】:

    标签: c++ apache-arrow


    【解决方案1】:

    好的,Arrow documentation site 中根本没有记录,所以我从 Arrow 源代码中收集了它。我希望有人可以推荐一个更简单/更官方的方法。

    我使用the Arrow example code生成arrow::Table,然后使用以下C++编写:

    #include "arrow/io/api.h"
    #include "arrow/ipc/feather.h"
    
    // ...
    std::shared_ptr<arrow::Table> table = //...;
    std::shared_ptr<FileOutputStream> file;
    ARROW_ASSIGN_OR_RAISE(file, FileOutputStream::Open(filename, /*append=*/true));
    ARROW_RETURN_NOT_OK(arrow::ipc::feather::WriteTable(*table, file.get()));
    ARROW_RETURN_NOT_OK(file->Close());
    

    以及从 Python 中读取的以下内容。

    import pyarrow as pa
    import pyarrow.feather as feather
    
    with pa.memory_map('myfile.feather', 'r') as stream:
        table = feather.read_feather(stream)
    print(table)
    

    Python 的代码输出是:

    $ python read_feather.py
       id  cost  cost_components
    0   1   1.0            [1.0]
    1   2   2.0       [1.0, 2.0]
    2   3   3.0  [1.0, 2.0, 3.0]
    

    【讨论】:

    • 这对我尝试用 C++ 编写表帮助很大。您是否有任何关于如何读回羽毛文件 C++ 的示例?根据您的示例,从 python 中非常容易,但我无法在任何地方找到从 C++ 读取它的示例
    猜你喜欢
    • 2021-06-02
    • 2020-06-20
    • 1970-01-01
    • 2021-06-12
    • 2021-01-13
    • 2019-06-18
    • 2018-08-22
    • 2021-08-28
    • 2019-05-03
    相关资源
    最近更新 更多