Skip to content

Commit

Permalink
Fix incorrect downcast in estimated_size_bytes (jorgecarleitao#1351)
Browse files Browse the repository at this point in the history
  • Loading branch information
jleibs authored and ritchie46 committed Mar 29, 2023
1 parent a529955 commit 8741bad
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/compute/aggregate/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub fn estimated_bytes_size(array: &dyn Array) -> usize {
+ validity_size(array.validity())
}
FixedSizeList => {
let array = array.as_any().downcast_ref::<ListArray<i64>>().unwrap();
let array = array.as_any().downcast_ref::<FixedSizeListArray>().unwrap();
estimated_bytes_size(array.values().as_ref()) + validity_size(array.validity())
}
LargeList => {
Expand Down
15 changes: 14 additions & 1 deletion tests/it/compute/aggregate/memory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use arrow2::{array::*, compute::aggregate::estimated_bytes_size};
use arrow2::{
array::*,
compute::aggregate::estimated_bytes_size,
datatypes::{DataType, Field},
};

#[test]
fn primitive() {
Expand All @@ -17,3 +21,12 @@ fn utf8() {
let a = Utf8Array::<i32>::from_slice(["aaa"]);
assert_eq!(3 + 2 * std::mem::size_of::<i32>(), estimated_bytes_size(&a));
}

#[test]
fn fixed_size_list() {
let data_type =
DataType::FixedSizeList(Box::new(Field::new("elem", DataType::Float32, false)), 3);
let values = Box::new(Float32Array::from_slice([1.0, 2.0, 3.0, 4.0, 5.0, 6.0]));
let a = FixedSizeListArray::new(data_type, values, None);
assert_eq!(6 * std::mem::size_of::<f32>(), estimated_bytes_size(&a));
}

0 comments on commit 8741bad

Please sign in to comment.