-
Notifications
You must be signed in to change notification settings - Fork 794
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
[ffi] Fix arrow-array null_count error during conversion from C to Rust #6674
Conversation
arrow-data/src/ffi.rs
Outdated
if self.null_count >= 0 { | ||
Some(self.null_count as usize) | ||
} else { | ||
None | ||
} |
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 self.null_count >= 0 { | |
Some(self.null_count as usize) | |
} else { | |
None | |
} | |
self.null_count.try_into().ok()? |
Perhaps, or using bool::then_some
if you wish to be more explicit
arrow-array/src/ffi.rs
Outdated
ffi_array.set_null_count(-1); | ||
assert_eq!(None, ffi_array.null_count()); | ||
let null_data = unsafe { from_ffi_and_data_type(ffi_array, DataType::Null) }.unwrap(); | ||
assert_eq!(10, null_data.null_count()); |
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.
assert_eq!(10, null_data.null_count()); | |
assert_eq!(0, null_data.null_count()); |
The null count for a NullArray should be 0, I know it is weird...
arrow-data/src/ffi.rs
Outdated
@@ -267,8 +267,19 @@ impl FFI_ArrowArray { | |||
|
|||
/// the null count of the array | |||
#[inline] | |||
pub fn null_count(&self) -> usize { | |||
self.null_count as usize | |||
pub fn null_count(&self) -> Option<usize> { |
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.
Unfortunately as written this is a breaking change, perhaps we could add a null_count_checked or something to avoid this?
Hi, @tustvold , Thanks for your review. I follow your suggestion and updated the PR, please review it again, thanks. |
Which issue does this PR close?
Closes #6497
Rationale for this change
What changes are included in this PR?
Option<usize>
, and return None if the value of null_count < 0.Option<usize>
, ArrayData will initialize if value is None.Are there any user-facing changes?
No