Skip to content

Commit e5e5970

Browse files
committed
chore(cubestore): Make columns_vec_buffer_size use min_credited_buffer_size
1 parent 4c5011e commit e5e5970

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,28 @@
11
use datafusion::arrow::array::ArrayRef;
2+
use datafusion::arrow::datatypes::DataType;
23
use datafusion::arrow::record_batch::RecordBatch;
34

45
pub fn record_batch_buffer_size(batch: &RecordBatch) -> usize {
56
columns_vec_buffer_size(batch.columns())
67
}
78
pub fn columns_vec_buffer_size(columns: &[ArrayRef]) -> usize {
8-
columns
9-
.iter()
10-
.fold(0, |size, col| size + col.get_buffer_memory_size())
9+
let mut sum = 0;
10+
for col in columns {
11+
let buffer_memory_size = col.get_buffer_memory_size();
12+
13+
// Add a minimum batch size for the column for primitive types. For simplicity (to avoid
14+
// needing a parallel implementation of Array::get_buffer_memory_size for every type of
15+
// Array) and due to lack of necessity, we don't recursively handle complex column types (such as
16+
// structs).
17+
let old_batch_size = 4096;
18+
let data_type = col.data_type();
19+
let min_credited_buffer_size = if data_type == &DataType::Boolean {
20+
old_batch_size / 8
21+
} else {
22+
data_type.primitive_width().unwrap_or(0) * old_batch_size
23+
};
24+
25+
sum += min_credited_buffer_size.max(buffer_memory_size);
26+
}
27+
sum
1128
}

0 commit comments

Comments
 (0)