Skip to content

Commit 2a34499

Browse files
committed
Optimize array_ndims
1 parent ad2e652 commit 2a34499

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

datafusion/functions-nested/src/dimension.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
2020
use arrow::array::{
2121
Array, ArrayRef, GenericListArray, ListArray, OffsetSizeTrait, UInt64Array,
22-
UInt64Builder,
2322
};
2423
use arrow::datatypes::{
2524
DataType,
@@ -220,17 +219,10 @@ pub fn array_ndims_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
220219
fn general_list_ndims<O: OffsetSizeTrait>(
221220
array: &GenericListArray<O>,
222221
) -> Result<ArrayRef> {
223-
let mut builder = UInt64Builder::with_capacity(array.len());
224222
let ndims = list_ndims(array.data_type());
225-
for arr in array.iter() {
226-
if arr.is_some() {
227-
builder.append_value(ndims)
228-
} else {
229-
builder.append_null()
230-
}
231-
}
232-
233-
Ok(Arc::new(builder.finish()))
223+
let data = vec![ndims; array.len()];
224+
let result = UInt64Array::new(data.into(), array.nulls().cloned());
225+
Ok(Arc::new(result))
234226
}
235227

236228
match array.data_type() {

0 commit comments

Comments
 (0)