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

add from_slice trait to ease arrow2 migration #1588

Merged
merged 2 commits into from
Jan 17, 2022
Merged

add from_slice trait to ease arrow2 migration #1588

merged 2 commits into from
Jan 17, 2022

Conversation

jimexist
Copy link
Member

@jimexist jimexist commented Jan 16, 2022

Which issue does this PR close?

Closes #.

Rationale for this change

Per #1556 - this trait is added to ease migration to arrow2:

  1. PrimitiveArray::from vec can be replaced with PrimitiveArray::from_slice with a slice

What changes are included in this PR?

Are there any user-facing changes?

@github-actions github-actions bot added the datafusion Changes in the datafusion crate label Jan 16, 2022
@jimexist jimexist requested a review from houqp January 16, 2022 14:25
@jimexist jimexist added this to the arrow2 milestone Jan 16, 2022
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Great idea @jimexist -- thank you!

The code looks good to me

let array_data = ArrayData::builder(T::DATA_TYPE)
.len(slice.len())
.add_buffer(Buffer::from_slice_ref(&slice));
let array_data = unsafe { array_data.build_unchecked() };
Copy link
Contributor

Choose a reason for hiding this comment

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

I had to double check myself, but I think this is good sound (This is not valid for BooleanType) but BooleanType doesn't implement ArrowPrimitiveType 👍

https://docs.rs/arrow/7.0.0/arrow/datatypes/trait.ArrowPrimitiveType.html

Copy link
Member Author

Choose a reason for hiding this comment

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

actually this was copied from the From<Vec part in ArrowPrimitiveType

similar changes can be done for booleans and string arrays but it can happen later

Copy link
Member Author

Choose a reason for hiding this comment

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

@alamb support for boolean, str, and bin array types are added in:

@jimexist jimexist merged commit f027e5f into master Jan 17, 2022
@houqp
Copy link
Member

houqp commented Jan 17, 2022

Thank you @jimexist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants