英文:
How can I create Arrow Builders from a Schema in Rust?
问题
根据箭头模式,创建每个字段的构建器的惯用方法是什么,以便我可以填充这些字段与与模式匹配的值,以便稍后将它们写入使用此模式的 Parquet 文件?
例如,给定以下模式:
let foo_field = Field::new("FOO", DataType::Utf8, false);
let baa_field = Field::new("BAA", DataType::UInt16, false);
let schema = Schema::new(vec![
foo_field,
baa_field,
]);
然后,您可以创建与模式匹配的构建器,使用以下方法:
let mut foo_builder = GenericStringBuilder::<i32>::new();
let mut baa_builder = UInt16Array::builder(batch_size);
但我理想情况下想要从模式中创建它们,以便我可以确保它们匹配,但我看不到如何做到这一点。
为了背景信息,我的依赖关系目前是:
[dependencies]
arrow = "37.0.0"
parquet = "37.0.0"
itertools = "0.10.5"
但如果需要,我可以考虑更改库和版本。
英文:
Given an arrow schema, what would be the idiomatic way to create builders for each field so that I can populate these fields with values that match the schema so that they may later be written to a parquet file that uses this schema?
For example, given the schema:
let foo_field = Field::new("FOO", DataType::Utf8, false);
let baa_field = Field::new("BAA", DataType::UInt16, false);
let schema = Schema::new(vec![
foo_field,
baa_field,
]);
Then I can create builders which will match the schema using
let mut foo_builder = GenericStringBuilder::<i32>::new();
let mut baa_builder = UInt16Array::builder(batch_size);
but I would ideally like to create them from the schema so that I can be certain they will match but I can't see a way to do this.
For context, my dependencies are currently:
[dependencies]
arrow = "37.0.0"
parquet = "37.0.0"
itertools = "0.10.5"
but I am open to changing libraries and versions if needed.
答案1
得分: 1
arrow-rs提供了make_builder API,用于根据数据类型动态创建构建器。然而,目前不支持某些类型(例如列表和映射)。
英文:
arrow-rs do have a make_builder API to dynamically create builders from data types. however some types (for example lists and maps) are not supported at the moment.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论