-
Notifications
You must be signed in to change notification settings - Fork 692
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
Allow primitive array creation from iterators of PrimitiveTypes (as well as Option
)
#1367
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1367 +/- ##
==========================================
+ Coverage 82.98% 83.04% +0.05%
==========================================
Files 181 181
Lines 52932 53025 +93
==========================================
+ Hits 43926 44033 +107
+ Misses 9006 8992 -14
Continue to review full report at Codecov.
|
cc @alamb |
Thanks @viirya -- Sorry for the delay in review; I was out last week so I am am still catching up -- I'll add this one to my review queue and hope to get to it shortly. |
Thank you @alamb ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is very clever @viirya -- thank you very much.
I have a concern (but no specific suggestions just yet)
Today if people impl Borrow<i8> for MyAwesomeType
then I think (untested) they can create arrays from an iterator of MyAwesomeType
which they might not be able to do after this PR 🤔 Though perhaps they just need to implement ArrowPrimitiveTypeNative
I tried a little to figure out a clever way to implement the conversion using a trait that is a superset of Borrow
to make it backwards compatible and more general. Thus instead of
impl<T: ArrowPrimitiveType, Ptr: Borrow<Option<<T as ArrowPrimitiveType>::Native>>>
FromIterator<Ptr> for PrimitiveArray<T>
It would look something like
impl<T: ArrowPrimitiveType, Ptr: BorrowAsOption<<T as ArrowPrimitiveType>::Native>>
FromIterator<Ptr> for PrimitiveArray<T>
..
pub trait BorrowAsOption<T: ArrowPrimitiveType> {
fn as_native(&self) -> Option<&<T as ArrowPrimitiveType>::Native>;
}
But my mind was being blown by type errors.
arrow/src/array/array_primitive.rs
Outdated
impl<T: ArrowPrimitiveType, Ptr: Borrow<Option<<T as ArrowPrimitiveType>::Native>>> | ||
FromIterator<Ptr> for PrimitiveArray<T> | ||
#[derive(Debug)] | ||
pub struct ArrowPrimitiveTypeNative<T: ArrowPrimitiveType> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub struct ArrowPrimitiveTypeNative<T: ArrowPrimitiveType> { | |
struct ArrowPrimitiveTypeNative<T: ArrowPrimitiveType> { |
I wonder if this needs to be pub
?
If it does need to be pub I think we should probably document it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If people want to use their types to create arrays from an iterator, they need to implement From
for ArrowPrimitiveTypeNative
. So I guess we need it to be pub
? I will document it.
I guess you mean
Not sure if I understand above way. Seems people still need to implement |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I understand above way. Seems people still need to implement BorrowAsOption, so it's still not backwards compatible.
Yeah, after more thought here I can't come up with anything better
Some documentation comments on ArrowPrimitiveTypeNative
would definitely be useful. I wonder if changing its name to something like NativeAdapter
would make its purpose clearer.
I wonder if we need something similar for str
and bool
to make StringArrays
and BooleanArrays
(can do as a follow on PR)
maybe @shepmaster or @carols10cents has some alternate suggestions
Thanks @alamb ! Just renamed |
Option
)
Thanks @viirya -- this looks great |
Thanks @alamb for your review and suggestion! |
Which issue does this PR close?
Closes #1298.
Rationale for this change
What changes are included in this PR?
Are there any user-facing changes?