Skip to content

Commit

Permalink
Adjust calculation for validity bitmap
Browse files Browse the repository at this point in the history
  • Loading branch information
jhorstmann committed Jun 29, 2021
1 parent 410f48d commit 57bbe92
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
14 changes: 13 additions & 1 deletion arrow/src/array/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ where
#[cfg(test)]
mod tests {
use super::*;
use std::iter::FromIterator;

#[test]
fn test_empty_primitive() {
Expand Down Expand Up @@ -683,6 +682,10 @@ mod tests {
std::mem::size_of::<NullArray>(),
null_arr.get_array_memory_size()
);
assert_eq!(
std::mem::size_of::<NullArray>(),
std::mem::size_of::<ArrayData>(),
);
}

#[test]
Expand All @@ -708,6 +711,15 @@ mod tests {
.build(),
);

// expected size is the size of the PrimitiveArray struct,
// which includes the optional validity buffer
// plus one buffer on the heap
assert_eq!(
std::mem::size_of::<PrimitiveArray<Int64Type>>()
+ std::mem::size_of::<Buffer>(),
empty_with_bitmap.get_array_memory_size()
);

// substract empty array to avoid magic numbers for the size of additional fields
// the size of the validity bitmap is rounded up to 64 bytes
assert_eq!(
Expand Down
7 changes: 5 additions & 2 deletions arrow/src/array/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,14 @@ impl ArrayData {

// Calculate rest of the fields top down which contain actual data
for buffer in &self.buffers {
size += mem::size_of_val(&buffer);
size += mem::size_of::<Buffer>();
size += buffer.capacity();
}
if let Some(bitmap) = &self.null_bitmap {
size += bitmap.get_array_memory_size()
// this includes the size of the bitmap struct itself, since it is stored directly in
// this struct we already counted those bytes in the size_of_val(self) above
size += bitmap.get_array_memory_size();
size -= mem::size_of::<Bitmap>();
}
for child in &self.child_data {
size += child.get_array_memory_size();
Expand Down

0 comments on commit 57bbe92

Please sign in to comment.