首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在C++中写入Apache Arrow feather文件?

如何在C++中写入Apache Arrow feather文件?
EN

Stack Overflow用户
提问于 2020-07-24 11:15:08
回答 1查看 598关注 0票数 0

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

假设我们有一个arrow::Table实例,如何将它的内容写入到一个feather文件中?

EN

回答 1

Stack Overflow用户

发布于 2020-07-24 12:02:18

好的,这在Arrow documentation site中根本没有文档,所以我从箭头源代码中收集了它。我希望有人能推荐一种更简单/更正式的方法。

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

代码语言:javascript
复制
#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中读取以下内容。

代码语言:javascript
复制
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的代码输出是:

代码语言:javascript
复制
$ 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]
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63066222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档