@@ -11,10 +11,10 @@ use vortex_error::vortex_ensure;
1111
1212use crate :: ArrayRef ;
1313use crate :: ExecutionCtx ;
14- use crate :: arrays:: ListView ;
1514use crate :: arrays:: ListViewArray ;
1615use crate :: arrays:: PrimitiveArray ;
1716use crate :: arrays:: listview:: ListViewDataParts ;
17+ use crate :: arrays:: listview:: ListViewRebuildMode ;
1818use crate :: arrow:: executor:: validity:: to_arrow_null_buffer;
1919use crate :: arrow:: session:: ArrowSessionExt ;
2020use crate :: builtins:: ArrayBuiltins ;
@@ -27,15 +27,16 @@ pub(super) fn to_arrow_list_view<O: OffsetSizeTrait + IntegerPType>(
2727 elements_field : & FieldRef ,
2828 ctx : & mut ExecutionCtx ,
2929) -> VortexResult < arrow_array:: ArrayRef > {
30- // Check for Vortex ListViewArray and convert directly.
31- let array = match array. try_downcast :: < ListView > ( ) {
32- Ok ( array) => return list_view_to_list_view :: < O > ( array, elements_field, ctx) ,
33- Err ( array) => array,
30+ let array = array. execute :: < ListViewArray > ( ctx) ?;
31+
32+ // If array is sparse, rebuild before handing it to Arrow
33+ let array = if array. should_rebuild ( false , ctx) ? {
34+ array. rebuild ( ListViewRebuildMode :: MakeZeroCopyToList ) ?
35+ } else {
36+ array
3437 } ;
3538
36- // Otherwise, we execute to ListViewArray and convert.
37- let list_view_array = array. execute :: < ListViewArray > ( ctx) ?;
38- list_view_to_list_view :: < O > ( list_view_array, elements_field, ctx)
39+ list_view_to_list_view :: < O > ( array, elements_field, ctx)
3940}
4041
4142fn list_view_to_list_view < O : OffsetSizeTrait + IntegerPType > (
0 commit comments