Skip to content

Commit

Permalink
Fix null_count for Null type
Browse files Browse the repository at this point in the history
  • Loading branch information
pitrou committed Nov 16, 2023
1 parent 80b71cd commit 37f87cd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion arrow-data/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,12 @@ impl FFI_ArrowArray {
.collect::<Box<_>>();
let n_children = children.len() as i64;

// As in the IPC format, emit null_count = length for Null type
let null_count = match data.data_type() {
DataType::Null => data.len(),
_ => data.null_count(),
};

// create the private data owning everything.
// any other data must be added here, e.g. via a struct, to track lifetime.
let mut private_data = Box::new(ArrayPrivateData {
Expand All @@ -179,7 +185,7 @@ impl FFI_ArrowArray {

Self {
length: data.len() as i64,
null_count: data.null_count() as i64,
null_count: null_count as i64,
offset: data.offset() as i64,
n_buffers,
n_children,
Expand Down
1 change: 1 addition & 0 deletions arrow-integration-testing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ fn cdata_integration_import_batch_and_compare_to_json(
let imported_array = unsafe { std::ptr::replace(c_array, FFI_ArrowArray::empty()) };
let imported_array =
from_ffi_and_data_type(imported_array, DataType::Struct(schema.fields.clone()))?;
imported_array.validate_full()?;
let imported_batch = RecordBatch::from(StructArray::from(imported_array));

compare_batches(&json_batch, &imported_batch)
Expand Down
5 changes: 4 additions & 1 deletion arrow/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,10 @@ impl<'a> ImportedArrowArray<'a> {
fn consume(self) -> Result<ArrayData> {
let len = self.array.len();
let offset = self.array.offset();
let null_count = self.array.null_count();
let null_count = match &self.data_type {
DataType::Null => 0,
_ => self.array.null_count(),
};

let data_layout = layout(&self.data_type);
let buffers = self.buffers(data_layout.can_contain_null_mask)?;
Expand Down

0 comments on commit 37f87cd

Please sign in to comment.