【发布时间】:2021-02-03 16:26:12
【问题描述】:
我正在尝试使用 Apache Arrow 提供的 C++ StreamWriter 类。
使用StreamWriter 的唯一示例使用低级 Parquet API,即
parquet::schema::NodeVector fields;
fields.push_back(parquet::schema::PrimitiveNode::Make(
"string_field", parquet::Repetition::OPTIONAL, parquet::Type::BYTE_ARRAY,
parquet::ConvertedType::UTF8));
fields.push_back(parquet::schema::PrimitiveNode::Make(
"char_field", parquet::Repetition::REQUIRED, parquet::Type::FIXED_LEN_BYTE_ARRAY,
parquet::ConvertedType::NONE, 1));
auto node = std::static_pointer_cast<parquet::schema::GroupNode>(
parquet::schema::GroupNode::Make("schema", parquet::Repetition::REQUIRED, fields));
最终结果是std::shared_ptr<parquet::schema::GroupNode>,然后可以将其传递给StreamWriter。
是否可以使用StreamWriter 构建和使用“高级”箭头模式?使用 WriteTable 函数(非流式传输)时支持它们,但我没有找到将其与流式传输 API 一起使用的示例。
当然,我可以使用低级 API,但在创建大型复杂架构时它非常冗长,我更愿意(但不需要)使用高级 Arrow 架构机制。
例如,
std::shared_ptr<arrow::io::FileOutputStream> outfile_;
PARQUET_ASSIGN_OR_THROW(outfile_, arrow::io::FileOutputStream::Open("test.parquet"));
// construct an arrow schema
auto schema = arrow::schema({arrow::field("field1", arrow::int64()),
arrow::field("field2", arrow::float64()),
arrow::field("field3", arrow::float64())});
// build the writer properties
parquet::WriterProperties::Builder builder;
auto properties = builder.build()
// my current best attempt at converting the Arrow schema to a Parquet schema
std::shared_ptr<parquet::SchemaDescriptor> parquet_schema;
parquet::arrow::ToParquetSchema(schema.get(), *properties, &parquet_schema); // parquet_schema is now populated
// and now I try and build the writer - this fails
auto writer = parquet::ParquetFileWriter::Open(outfile_, parquet_schema->group_node(), properties);
最后一行失败是因为parquet_schema->group_node()(这是我知道的唯一可以访问架构的GroupNode 的方法)返回const GroupNode*,而ParquetFileWriter::Open) 需要std::shared_ptr<GroupNode>。
我不确定放弃返回的组节点的常量并强制它进入::Open() 调用是StreamWriter 的官方支持(或正确)用法。
我想做的事可能吗?
【问题讨论】:
标签: c++ parquet apache-arrow