-
Notifications
You must be signed in to change notification settings - Fork 796
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API inconsistency of ListBuilder make it hard to use as nested builder #5098
Comments
I'm not sure of the history here, but the current design does allow for some advantages when the types are known ahead of time https://docs.rs/arrow-array/latest/arrow_array/builder/index.html#custom-builders Perhaps we could allow creating a ListBuilder with a boxed builder if one so wished, i.e. |
If we know the row column types in compile time, it is okay as shown in the example Currently I can use macro to create So any situation that needs to have |
What did you think of deriving ArrayBuilder for |
I think it could make constructing DataType::List(field) => {
match field.data_type() {
DataType::Boolean => {
...
Box::new(ListBuilder::new(*builder))
}
DataType::Int8 => {
...
}
...
} For nested |
BTW, I can work on this in spare time during my travel in next week to see if it works. (if you don't have time to work on this). |
|
Is your feature request related to a problem or challenge? Please describe what you are trying to do.
I'm working on something to build various array builders (could be nested) based on different data types. The purpose is to have builders used to append values from values of rows.
For primitive and struct types, they are working well.
But
ListBuilder
(I thinkMapBuilder
has the same issue) is an exception. Its API design (it has a type parameterT: ArrayBuilder
) is different from other builders. This inconsistency makes harder to putListBuilder
as a same piece like other builders.For example, this crate has an API
make_builder
which returnsBox<dyn ArrayBuilder>
. Currently it doesn't handleDataType::List
. Ideally, forListBuilder
we should be able to do:But we cannot do it because
ListBuilder
requires type parameter of its value builder. Thought we can write a macro to dointo_box_any().downcast::<$builder_type>
on the returnedBox<dyn ArrayBuilder>
frommake_builder
to get concrete owned value of value builder. And that is what I did locally. But it only works for primitive builders.For nested list types, we need to have nested type parameter of the nested
ListBuilder
type. I'm not sure how we can dynamically create a deeply nested type parameter in runtime?Since
ListBuilder
has additional type parameter, it means a macro that can work on all other builder types can not work on it. Because it requires a second macro to handle different element builder type cases.Describe the solution you'd like
I am wondering if we can remove the type parameter from
ListBuilder
and make its value builder asBox<dyn ArrayBuilder>
asStructBuilder
.Describe alternatives you've considered
Additional context
The text was updated successfully, but these errors were encountered: