【发布时间】:2020-11-13 21:15:40
【问题描述】:
将数据写入 Apache Arrow 支持的 Feather format 的 C++ 代码的最小示例是什么?该文件稍后将用于从 Python 代码中进行映射读取。
假设我们有一个arrow::Table的实例,如何将其内容写入羽毛文件?
【问题讨论】:
标签: c++ apache-arrow
将数据写入 Apache Arrow 支持的 Feather format 的 C++ 代码的最小示例是什么?该文件稍后将用于从 Python 代码中进行映射读取。
假设我们有一个arrow::Table的实例,如何将其内容写入羽毛文件?
【问题讨论】:
标签: c++ apache-arrow
好的,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]
【讨论】: