Skip to content
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

RecordBatch normalization (flattening) #6758

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ngli-me
Copy link
Contributor

@ngli-me ngli-me commented Nov 20, 2024

Which issue does this PR close?

Closes #6369.

Rationale for this change

Adds normalization (flattening) for RecordBatch, with normalization via Schema. Based on pandas/pola-rs.

What changes are included in this PR?

Are there any user-facing changes?

@ngli-me ngli-me changed the title Feature/record batch flatten RecordBatch normalization (flattening) Nov 20, 2024
@ngli-me ngli-me changed the title RecordBatch normalization (flattening) RecordBatch normalization (flattening) Nov 20, 2024
… iterative function for `RecordBatch`. Not sure which one is better currently.
@github-actions github-actions bot added the arrow Changes to the arrow crate label Nov 23, 2024
Copy link
Contributor Author

@ngli-me ngli-me left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some questions regarding the implementation of this, since the one example from PyArrow doesn't seem to clarify on the edge cases here. Normalizing the Schema seems fairly straight forward to me, I'm just not sure on

  1. Whether the iterative or recursive approach is better (or something I missed)
  2. If DataType::Struct is the only DataType that requires flattening. To me, it looks like that's the only one that can contained nested Fields.

(I'm also not sure if I'm missing something with unwrapping like a List<Struct>)

Any feedback/help would be appreciated!

arrow-array/src/record_batch.rs Outdated Show resolved Hide resolved
arrow-array/src/record_batch.rs Outdated Show resolved Hide resolved
let field_name = field.name().as_str();
new_fields = [
new_fields,
Self::normalizer(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it's better to have it be recursive or iterative.

@ngli-me ngli-me marked this pull request as ready for review November 23, 2024 19:03
@ngli-me ngli-me marked this pull request as draft November 23, 2024 23:30
(c.clone(), Arc::new(c_field.clone()) as ArrayRef),
]));

/*let exclamation_field = Arc::new(StructArray::from(vec![
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this should work to me, based on the schema, but I get an error when trying to construct this Field, not sure what I'm missing here.

error[E0277]: the trait boundstd::sync::Arc<struct_array::StructArray>: array::Arrayis not satisfied --> arrow-array/src/record_batch.rs:1353:27 | 1353 | (one.clone(), Arc::new(one_field.clone()) as ArrayRef), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ the traitarray::Arrayis not implemented forstd::sync::Arc<struct_array::StructArray>| = help: the traitarray::Arrayis implemented forstd::sync::Arc<(dyn array::Array + 'static)>= note: required for the cast fromstd::sync::Arc<std::sync::Arc<struct_array::StructArray>>tostd::sync::Arc<(dyn array::Array + 'static)>

@ngli-me ngli-me marked this pull request as ready for review November 25, 2024 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrow Changes to the arrow crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support RecordBatch.flatten
1 participant