File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed
rust/cubestore/cubestore/src/util Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 11use datafusion:: arrow:: array:: ArrayRef ;
2+ use datafusion:: arrow:: datatypes:: DataType ;
23use datafusion:: arrow:: record_batch:: RecordBatch ;
34
45pub fn record_batch_buffer_size ( batch : & RecordBatch ) -> usize {
56 columns_vec_buffer_size ( batch. columns ( ) )
67}
78pub 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}
You can’t perform that action at this time.
0 commit comments