@@ -94,6 +94,7 @@ impl BlockReader {
94
94
} ;
95
95
96
96
let mut blocks = Vec :: with_capacity ( record_batches. len ( ) ) ;
97
+ let mut array_cache_buffer = HashMap :: with_capacity ( record_batches. len ( ) ) ;
97
98
98
99
let mut offset = 0 ;
99
100
for record_batch in record_batches {
@@ -126,18 +127,17 @@ impl BlockReader {
126
127
Some ( DataItem :: RawData ( data) ) => {
127
128
// get the deserialized arrow array, which may be a nested array
128
129
let arrow_array = column_by_name ( & record_batch, & name_paths[ i] ) ;
129
- if !column_node. is_nested {
130
- if let Some ( cache) = & array_cache {
131
- let meta = column_metas. get ( & field. column_id ) . unwrap ( ) ;
132
- let ( offset, len) = meta. offset_length ( ) ;
133
- let key = TableDataCacheKey :: new (
134
- block_path,
135
- field. column_id ,
136
- offset,
137
- len,
138
- ) ;
139
- cache. insert ( key. into ( ) , ( arrow_array. clone ( ) , data. len ( ) ) ) ;
140
- }
130
+ if !column_node. is_nested && array_cache. is_some ( ) {
131
+ let meta = column_metas. get ( & field. column_id ) . unwrap ( ) ;
132
+ let ( offset, len) = meta. offset_length ( ) ;
133
+ let key =
134
+ TableDataCacheKey :: new ( block_path, field. column_id , offset, len) ;
135
+ array_cache_buffer
136
+ . entry ( key)
137
+ . and_modify ( |v : & mut Vec < _ > | {
138
+ v. push ( ( arrow_array. clone ( ) , data. len ( ) ) )
139
+ } )
140
+ . or_insert ( vec ! [ ( arrow_array. clone( ) , data. len( ) ) ] ) ;
141
141
}
142
142
Value :: from_arrow_rs ( arrow_array, & data_type) ?
143
143
}
@@ -160,6 +160,21 @@ impl BlockReader {
160
160
blocks. push ( DataBlock :: new ( columns, num_rows_record_batch) ) ;
161
161
}
162
162
163
+ // TODO doc this
164
+ if let Some ( array_cache) = & array_cache {
165
+ for ( key, items) in array_cache_buffer {
166
+ let mut arrays = Vec :: with_capacity ( items. len ( ) ) ;
167
+ let mut len = 0 ;
168
+ for ( array, size) in & items {
169
+ arrays. push ( array. as_ref ( ) ) ;
170
+ len += size;
171
+ }
172
+ use arrow:: compute:: concat;
173
+ let result = concat ( & arrays) ?;
174
+ array_cache. insert ( key. into ( ) , ( result, len) ) ;
175
+ }
176
+ }
177
+
163
178
Ok ( blocks)
164
179
}
165
180
}
0 commit comments