将数据写入Apache Arrow支持的Feather format的C++代码的最小示例是什么?该文件稍后将用于从Python代码中执行mmapped读取。
假设我们有一个arrow::Table实例,如何将它的内容写入到一个feather文件中?
发布于 2020-07-24 12:02:18
好的,这在Arrow documentation site中根本没有文档,所以我从箭头源代码中收集了它。我希望有人能推荐一种更简单/更正式的方法。
我使用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]https://stackoverflow.com/questions/63066222
复制相似问题