Skip to content

Commit

Permalink
Implement logical_null_count for more array types (#6704)
Browse files Browse the repository at this point in the history
Implement Array::logical_null_count() where it's easy to calculate
answer without relying on the default implementation which allocates.
  • Loading branch information
findepi authored Nov 9, 2024
1 parent 0e9abcd commit 6dea453
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 0 deletions.
5 changes: 5 additions & 0 deletions arrow-array/src/array/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,11 @@ impl<T: ByteArrayType> Array for GenericByteArray<T> {
self.nulls.as_ref()
}

fn logical_null_count(&self) -> usize {
// More efficient that the default implementation
self.null_count()
}

fn get_buffer_memory_size(&self) -> usize {
let mut sum = self.value_offsets.inner().inner().capacity();
sum += self.value_data.capacity();
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/array/byte_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ impl<T: ByteViewType + ?Sized> Array for GenericByteViewArray<T> {
self.nulls.as_ref()
}

fn logical_null_count(&self) -> usize {
// More efficient that the default implementation
self.null_count()
}

fn get_buffer_memory_size(&self) -> usize {
let mut sum = self.buffers.iter().map(|b| b.capacity()).sum::<usize>();
sum += self.views.inner().capacity();
Expand Down
4 changes: 4 additions & 0 deletions arrow-array/src/array/dictionary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,10 @@ impl<K: ArrowDictionaryKeyType, V: Sync> Array for TypedDictionaryArray<'_, K, V
self.dictionary.logical_nulls()
}

fn logical_null_count(&self) -> usize {
self.dictionary.logical_null_count()
}

fn is_nullable(&self) -> bool {
self.dictionary.is_nullable()
}
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/array/fixed_size_binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,11 @@ impl Array for FixedSizeBinaryArray {
self.nulls.as_ref()
}

fn logical_null_count(&self) -> usize {
// More efficient that the default implementation
self.null_count()
}

fn get_buffer_memory_size(&self) -> usize {
let mut sum = self.value_data.capacity();
if let Some(n) = &self.nulls {
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ impl Array for FixedSizeListArray {
self.nulls.as_ref()
}

fn logical_null_count(&self) -> usize {
// More efficient that the default implementation
self.null_count()
}

fn get_buffer_memory_size(&self) -> usize {
let mut size = self.values.get_buffer_memory_size();
if let Some(n) = self.nulls.as_ref() {
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/array/list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,11 @@ impl<OffsetSize: OffsetSizeTrait> Array for GenericListArray<OffsetSize> {
self.nulls.as_ref()
}

fn logical_null_count(&self) -> usize {
// More efficient that the default implementation
self.null_count()
}

fn get_buffer_memory_size(&self) -> usize {
let mut size = self.values.get_buffer_memory_size();
size += self.value_offsets.inner().inner().capacity();
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/array/list_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,11 @@ impl<OffsetSize: OffsetSizeTrait> Array for GenericListViewArray<OffsetSize> {
self.nulls.as_ref()
}

fn logical_null_count(&self) -> usize {
// More efficient that the default implementation
self.null_count()
}

fn get_buffer_memory_size(&self) -> usize {
let mut size = self.values.get_buffer_memory_size();
size += self.value_offsets.inner().capacity();
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/array/map_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ impl Array for MapArray {
self.nulls.as_ref()
}

fn logical_null_count(&self) -> usize {
// More efficient that the default implementation
self.null_count()
}

fn get_buffer_memory_size(&self) -> usize {
let mut size = self.entries.get_buffer_memory_size();
size += self.value_offsets.inner().inner().capacity();
Expand Down
4 changes: 4 additions & 0 deletions arrow-array/src/array/run_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,10 @@ impl<R: RunEndIndexType, V: Sync> Array for TypedRunArray<'_, R, V> {
self.run_array.logical_nulls()
}

fn logical_null_count(&self) -> usize {
self.run_array.logical_null_count()
}

fn is_nullable(&self) -> bool {
self.run_array.is_nullable()
}
Expand Down
5 changes: 5 additions & 0 deletions arrow-array/src/array/struct_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,11 @@ impl Array for StructArray {
self.nulls.as_ref()
}

fn logical_null_count(&self) -> usize {
// More efficient that the default implementation
self.null_count()
}

fn get_buffer_memory_size(&self) -> usize {
let mut size = self.fields.iter().map(|a| a.get_buffer_memory_size()).sum();
if let Some(n) = self.nulls.as_ref() {
Expand Down

0 comments on commit 6dea453

Please sign in to comment.