我试图使用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
。使用
WriteTable
函数(非流式)时,可以使用“高级”Arrow模式吗?但是在使用流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);
最后一行代码失败了,因为我所知道的唯一获取架构GroupNode访问权限的方式
parquet_schema->group_node()
返回了一个const GroupNode*
,而ParquetFileWriter::Open()
需要一个std::shared_ptr<GroupNode>
。
我不确定去除返回的组节点的常量性并将其强制转换为::Open()
调用是否是StreamWriter
的官方支持(或正确)的用法。我想要做的这件事是否可能?