如何在Rust中从Schema创建Arrow Builders?

huangapple go评论62阅读模式
英文:

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(&quot;FOO&quot;, DataType::Utf8, false);
let baa_field = Field::new(&quot;BAA&quot;, 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::&lt;i32&gt;::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 = &quot;37.0.0&quot;
parquet = &quot;37.0.0&quot;
itertools = &quot;0.10.5&quot;

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.

huangapple
  • 本文由 发表于 2023年4月19日 23:38:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/76056405.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定