@@ -247,6 +247,33 @@ fn serialize_compression(
247
247
}
248
248
}
249
249
250
+ fn set_variadic_buffer_counts ( _counts : & mut Vec < i64 > , array : & dyn Array ) {
251
+ match array. data_type ( ) {
252
+ DataType :: Struct ( _) => {
253
+ let array = array. as_any ( ) . downcast_ref :: < StructArray > ( ) . unwrap ( ) ;
254
+ for array in array. values ( ) {
255
+ set_variadic_buffer_counts ( _counts, array. as_ref ( ) )
256
+ }
257
+ }
258
+ DataType :: LargeList ( _) => {
259
+ let array = array. as_any ( ) . downcast_ref :: < ListArray < i64 > > ( ) . unwrap ( ) ;
260
+ set_variadic_buffer_counts ( _counts, array. values ( ) . as_ref ( ) )
261
+ }
262
+ DataType :: FixedSizeList ( _, _) => {
263
+ let array = array. as_any ( ) . downcast_ref :: < FixedSizeListArray > ( ) . unwrap ( ) ;
264
+ set_variadic_buffer_counts ( _counts, array. values ( ) . as_ref ( ) )
265
+ }
266
+ DataType :: Dictionary ( _, _, _) => {
267
+ let array = array
268
+ . as_any ( )
269
+ . downcast_ref :: < DictionaryArray < u32 > > ( )
270
+ . unwrap ( ) ;
271
+ set_variadic_buffer_counts ( _counts, array. values ( ) . as_ref ( ) )
272
+ }
273
+ _ => ( ) ,
274
+ }
275
+ }
276
+
250
277
/// Write [`Chunk`] into two sets of bytes, one for the header (ipc::Schema::Message) and the
251
278
/// other for the batch's data
252
279
fn chunk_to_bytes_amortized (
@@ -260,7 +287,10 @@ fn chunk_to_bytes_amortized(
260
287
arrow_data. clear ( ) ;
261
288
262
289
let mut offset = 0 ;
290
+ let mut variadic_buffer_counts = vec ! [ ] ;
291
+
263
292
for array in chunk. arrays ( ) {
293
+ set_variadic_buffer_counts ( & mut variadic_buffer_counts, array. as_ref ( ) ) ;
264
294
write (
265
295
array. as_ref ( ) ,
266
296
& mut buffers,
@@ -272,6 +302,12 @@ fn chunk_to_bytes_amortized(
272
302
)
273
303
}
274
304
305
+ let variadic_buffer_counts = if variadic_buffer_counts. is_empty ( ) {
306
+ None
307
+ } else {
308
+ Some ( variadic_buffer_counts)
309
+ } ;
310
+
275
311
let compression = serialize_compression ( options. compression ) ;
276
312
277
313
let message = arrow_format:: ipc:: Message {
@@ -282,6 +318,7 @@ fn chunk_to_bytes_amortized(
282
318
nodes : Some ( nodes) ,
283
319
buffers : Some ( buffers) ,
284
320
compression,
321
+ variadic_buffer_counts,
285
322
} ,
286
323
) ) ) ,
287
324
body_length : arrow_data. len ( ) as i64 ,
@@ -306,6 +343,15 @@ fn dictionary_batch_to_bytes<K: DictionaryKey>(
306
343
let mut buffers: Vec < arrow_format:: ipc:: Buffer > = vec ! [ ] ;
307
344
let mut arrow_data: Vec < u8 > = vec ! [ ] ;
308
345
346
+ let mut variadic_buffer_counts = vec ! [ ] ;
347
+ set_variadic_buffer_counts ( & mut variadic_buffer_counts, array. values ( ) . as_ref ( ) ) ;
348
+
349
+ let variadic_buffer_counts = if variadic_buffer_counts. is_empty ( ) {
350
+ None
351
+ } else {
352
+ Some ( variadic_buffer_counts)
353
+ } ;
354
+
309
355
let length = write_dictionary (
310
356
array,
311
357
& mut buffers,
@@ -329,6 +375,7 @@ fn dictionary_batch_to_bytes<K: DictionaryKey>(
329
375
nodes : Some ( nodes) ,
330
376
buffers : Some ( buffers) ,
331
377
compression,
378
+ variadic_buffer_counts,
332
379
} ) ) ,
333
380
is_delta : false ,
334
381
} ,
0 commit comments