Skip to content

Commit 6dea453

Browse files
authored
Implement logical_null_count for more array types (#6704)
Implement Array::logical_null_count() where it's easy to calculate answer without relying on the default implementation which allocates.
1 parent 0e9abcd commit 6dea453

10 files changed

+48
-0
lines changed

arrow-array/src/array/byte_array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ impl<T: ByteArrayType> Array for GenericByteArray<T> {
461461
self.nulls.as_ref()
462462
}
463463

464+
fn logical_null_count(&self) -> usize {
465+
// More efficient that the default implementation
466+
self.null_count()
467+
}
468+
464469
fn get_buffer_memory_size(&self) -> usize {
465470
let mut sum = self.value_offsets.inner().inner().capacity();
466471
sum += self.value_data.capacity();

arrow-array/src/array/byte_view_array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,11 @@ impl<T: ByteViewType + ?Sized> Array for GenericByteViewArray<T> {
583583
self.nulls.as_ref()
584584
}
585585

586+
fn logical_null_count(&self) -> usize {
587+
// More efficient that the default implementation
588+
self.null_count()
589+
}
590+
586591
fn get_buffer_memory_size(&self) -> usize {
587592
let mut sum = self.buffers.iter().map(|b| b.capacity()).sum::<usize>();
588593
sum += self.views.inner().capacity();

arrow-array/src/array/dictionary_array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,10 @@ impl<K: ArrowDictionaryKeyType, V: Sync> Array for TypedDictionaryArray<'_, K, V
866866
self.dictionary.logical_nulls()
867867
}
868868

869+
fn logical_null_count(&self) -> usize {
870+
self.dictionary.logical_null_count()
871+
}
872+
869873
fn is_nullable(&self) -> bool {
870874
self.dictionary.is_nullable()
871875
}

arrow-array/src/array/fixed_size_binary_array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,11 @@ impl Array for FixedSizeBinaryArray {
610610
self.nulls.as_ref()
611611
}
612612

613+
fn logical_null_count(&self) -> usize {
614+
// More efficient that the default implementation
615+
self.null_count()
616+
}
617+
613618
fn get_buffer_memory_size(&self) -> usize {
614619
let mut sum = self.value_data.capacity();
615620
if let Some(n) = &self.nulls {

arrow-array/src/array/fixed_size_list_array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ impl Array for FixedSizeListArray {
409409
self.nulls.as_ref()
410410
}
411411

412+
fn logical_null_count(&self) -> usize {
413+
// More efficient that the default implementation
414+
self.null_count()
415+
}
416+
412417
fn get_buffer_memory_size(&self) -> usize {
413418
let mut size = self.values.get_buffer_memory_size();
414419
if let Some(n) = self.nulls.as_ref() {

arrow-array/src/array/list_array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,11 @@ impl<OffsetSize: OffsetSizeTrait> Array for GenericListArray<OffsetSize> {
493493
self.nulls.as_ref()
494494
}
495495

496+
fn logical_null_count(&self) -> usize {
497+
// More efficient that the default implementation
498+
self.null_count()
499+
}
500+
496501
fn get_buffer_memory_size(&self) -> usize {
497502
let mut size = self.values.get_buffer_memory_size();
498503
size += self.value_offsets.inner().inner().capacity();

arrow-array/src/array/list_view_array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,11 @@ impl<OffsetSize: OffsetSizeTrait> Array for GenericListViewArray<OffsetSize> {
334334
self.nulls.as_ref()
335335
}
336336

337+
fn logical_null_count(&self) -> usize {
338+
// More efficient that the default implementation
339+
self.null_count()
340+
}
341+
337342
fn get_buffer_memory_size(&self) -> usize {
338343
let mut size = self.values.get_buffer_memory_size();
339344
size += self.value_offsets.inner().capacity();

arrow-array/src/array/map_array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ impl Array for MapArray {
380380
self.nulls.as_ref()
381381
}
382382

383+
fn logical_null_count(&self) -> usize {
384+
// More efficient that the default implementation
385+
self.null_count()
386+
}
387+
383388
fn get_buffer_memory_size(&self) -> usize {
384389
let mut size = self.entries.get_buffer_memory_size();
385390
size += self.value_offsets.inner().inner().capacity();

arrow-array/src/array/run_array.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ impl<R: RunEndIndexType, V: Sync> Array for TypedRunArray<'_, R, V> {
596596
self.run_array.logical_nulls()
597597
}
598598

599+
fn logical_null_count(&self) -> usize {
600+
self.run_array.logical_null_count()
601+
}
602+
599603
fn is_nullable(&self) -> bool {
600604
self.run_array.is_nullable()
601605
}

arrow-array/src/array/struct_array.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,11 @@ impl Array for StructArray {
378378
self.nulls.as_ref()
379379
}
380380

381+
fn logical_null_count(&self) -> usize {
382+
// More efficient that the default implementation
383+
self.null_count()
384+
}
385+
381386
fn get_buffer_memory_size(&self) -> usize {
382387
let mut size = self.fields.iter().map(|a| a.get_buffer_memory_size()).sum();
383388
if let Some(n) = self.nulls.as_ref() {

0 commit comments

Comments
 (0)