Skip to content

Commit 37f87cd

Browse files
committed
Fix null_count for Null type
1 parent 80b71cd commit 37f87cd

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

arrow-data/src/ffi.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ impl FFI_ArrowArray {
168168
.collect::<Box<_>>();
169169
let n_children = children.len() as i64;
170170

171+
// As in the IPC format, emit null_count = length for Null type
172+
let null_count = match data.data_type() {
173+
DataType::Null => data.len(),
174+
_ => data.null_count(),
175+
};
176+
171177
// create the private data owning everything.
172178
// any other data must be added here, e.g. via a struct, to track lifetime.
173179
let mut private_data = Box::new(ArrayPrivateData {
@@ -179,7 +185,7 @@ impl FFI_ArrowArray {
179185

180186
Self {
181187
length: data.len() as i64,
182-
null_count: data.null_count() as i64,
188+
null_count: null_count as i64,
183189
offset: data.offset() as i64,
184190
n_buffers,
185191
n_children,

arrow-integration-testing/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ fn cdata_integration_import_batch_and_compare_to_json(
247247
let imported_array = unsafe { std::ptr::replace(c_array, FFI_ArrowArray::empty()) };
248248
let imported_array =
249249
from_ffi_and_data_type(imported_array, DataType::Struct(schema.fields.clone()))?;
250+
imported_array.validate_full()?;
250251
let imported_batch = RecordBatch::from(StructArray::from(imported_array));
251252

252253
compare_batches(&json_batch, &imported_batch)

arrow/src/ffi.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ impl<'a> ImportedArrowArray<'a> {
271271
fn consume(self) -> Result<ArrayData> {
272272
let len = self.array.len();
273273
let offset = self.array.offset();
274-
let null_count = self.array.null_count();
274+
let null_count = match &self.data_type {
275+
DataType::Null => 0,
276+
_ => self.array.null_count(),
277+
};
275278

276279
let data_layout = layout(&self.data_type);
277280
let buffers = self.buffers(data_layout.can_contain_null_mask)?;

0 commit comments

Comments
 (0)