Skip to content

Commit ee1e4b2

Browse files
authored
fix: avoid ListBuilder (#5636)
1 parent 374882d commit ee1e4b2

File tree

2 files changed

+9
-25
lines changed

2 files changed

+9
-25
lines changed

deny.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ feature-depth = 1
1515
ignore = [
1616
# Paste is no longer maintained because its essentially "finished".
1717
"RUSTSEC-2024-0436",
18+
# rustls-pemfile is a hard requirement from object_store crate.
19+
# need to wait for them to release, see https://github.com/apache/arrow-rs-object-store/pull/565
20+
"RUSTSEC-2025-0134",
1821
]
1922

2023
[licenses]

vortex-array/src/arrow/compute/to_arrow/canonical.rs

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,11 @@ use crate::arrays::NullArray;
7171
use crate::arrays::PrimitiveArray;
7272
use crate::arrays::StructArray;
7373
use crate::arrays::VarBinViewArray;
74+
use crate::arrays::list_from_list_view;
7475
use crate::arrow::IntoArrowArray;
7576
use crate::arrow::array::ArrowArray;
7677
use crate::arrow::compute::ToArrowArgs;
7778
use crate::arrow::compute::to_arrow::null_buffer::to_null_buffer;
78-
use crate::builders::ArrayBuilder;
79-
use crate::builders::ListBuilder;
8079
use crate::compute::InvocationArgs;
8180
use crate::compute::Kernel;
8281
use crate::compute::Output;
@@ -530,28 +529,11 @@ fn to_arrow_list<O: IntegerPType + OffsetSizeTrait>(
530529
array: ListViewArray,
531530
element_field: Option<&FieldRef>,
532531
) -> VortexResult<ArrowArrayRef> {
533-
// Since `ListViewArray` can have lists stored out-of-order, we must rebuild the entire array.
534-
// We also can't use `list_from_list_view` because we need this specific `O` type for offsets.
535-
let mut list_builder = ListBuilder::<O>::with_capacity(
536-
array
537-
.dtype()
538-
.as_list_element_opt()
539-
.vortex_expect("`ListViewArray` somehow was not of type `List`")
540-
.clone(),
541-
array.dtype().nullability(),
542-
array.elements().len(), // This might be wrong, but it's better than nothing.
543-
array.len(),
544-
);
545-
546-
// TODO(connor)[ListView]: We can potentially make a generic version of `list_from_list_view`
547-
// over the offsets so we don't have to rewrite this.
548-
549-
list_builder.extend_from_array(&array.to_array());
550-
let list_array = list_builder.finish_into_list();
532+
// Convert listview -> list, via the fast path when possible.
533+
// TODO(aduffy): extend list_from_list_view to support target offsets/size PTypes
534+
// to avoid the copy below
535+
let list_array = list_from_list_view(array);
551536

552-
// Now that we have a normal `ListArray`, we can convert all the child arrays.
553-
554-
// Convert the child `elements` array to Arrow.
555537
let (elements, element_field) = {
556538
if let Some(element_field) = element_field {
557539
// Convert elements to the specific Arrow type the caller wants.
@@ -573,8 +555,7 @@ fn to_arrow_list<O: IntegerPType + OffsetSizeTrait>(
573555
};
574556

575557
// Convert the child `offsets` and `validity` array to Arrow.
576-
let offsets = list_array
577-
.offsets()
558+
let offsets = cast(list_array.offsets().as_ref(), &DType::from(O::PTYPE))?
578559
.to_primitive()
579560
.buffer::<O>()
580561
.into_arrow_offset_buffer();

0 commit comments

Comments
 (0)