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

[ffi] Fix arrow-array null_count error during conversion from C to Rust #6674

Merged
merged 4 commits into from
Nov 5, 2024

Conversation

adbmal
Copy link
Contributor

@adbmal adbmal commented Nov 2, 2024

Which issue does this PR close?

Closes #6497

Rationale for this change

What changes are included in this PR?

  1. Let FFI_ArrowArray null_count() function return Option<usize>, and return None if the value of null_count < 0.
  2. Pass FFI_ArrowArray null_count() to ArrayData 's null_count, which is also Option<usize>, ArrayData will initialize if value is None.
  3. Add UT to verify it.

Are there any user-facing changes?

No

@github-actions github-actions bot added the arrow Changes to the arrow crate label Nov 2, 2024
@adbmal adbmal marked this pull request as ready for review November 2, 2024 14:20
arrow-data/src/data.rs Outdated Show resolved Hide resolved
Comment on lines 272 to 276
if self.null_count >= 0 {
Some(self.null_count as usize)
} else {
None
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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

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());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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-array/src/ffi.rs Show resolved Hide resolved
@@ -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> {
Copy link
Contributor

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?

@tustvold tustvold added the api-change Changes to the arrow API label Nov 4, 2024
@adbmal
Copy link
Contributor Author

adbmal commented Nov 5, 2024

Hi, @tustvold , Thanks for your review. I follow your suggestion and updated the PR, please review it again, thanks.

arrow-data/src/ffi.rs Outdated Show resolved Hide resolved
arrow-data/src/ffi.rs Outdated Show resolved Hide resolved
arrow-array/src/ffi.rs Outdated Show resolved Hide resolved
arrow-data/src/ffi.rs Outdated Show resolved Hide resolved
@tustvold tustvold merged commit 88b296c into apache:master Nov 5, 2024
26 checks passed
@tustvold tustvold removed the api-change Changes to the arrow API label Nov 6, 2024
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
2 participants