MCPcopy Create free account
hub / github.com/apache/datafusion / align_array_dimensions

Function align_array_dimensions

datafusion/functions-nested/src/utils.rs:86–122  ·  view source on GitHub ↗
(
    args: Vec<ArrayRef>,
)

Source from the content-addressed store, hash-verified

84}
85
86pub(crate) fn align_array_dimensions<O: OffsetSizeTrait>(
87 args: Vec<ArrayRef>,
88) -> Result<Vec<ArrayRef>> {
89 let args_ndim = args
90 .iter()
91 .map(|arg| datafusion_common::utils::list_ndims(arg.data_type()))
92 .collect::<Vec<_>>();
93 let max_ndim = args_ndim.iter().max().unwrap_or(&0);
94
95 // Align the dimensions of the arrays
96 let aligned_args: Result<Vec<ArrayRef>> = args
97 .into_iter()
98 .zip(args_ndim.iter())
99 .map(|(array, ndim)| {
100 if ndim < max_ndim {
101 let mut aligned_array = Arc::clone(&array);
102 for _ in 0..(max_ndim - ndim) {
103 let data_type = aligned_array.data_type().to_owned();
104 let array_lengths = vec![1; aligned_array.len()];
105 let offsets = OffsetBuffer::<O>::from_lengths(array_lengths);
106
107 aligned_array = Arc::new(GenericListArray::<O>::try_new(
108 Arc::new(Field::new_list_field(data_type, true)),
109 offsets,
110 aligned_array,
111 None,
112 )?)
113 }
114 Ok(aligned_array)
115 } else {
116 Ok(Arc::clone(&array))
117 }
118 })
119 .collect();
120
121 aligned_args
122}
123
124/// Computes a BooleanArray indicating equality or inequality between elements in a list array and a specified element array.
125///

Callers

nothing calls this directly

Calls 8

list_ndimsFunction · 0.85
newFunction · 0.85
collectMethod · 0.80
mapMethod · 0.45
iterMethod · 0.45
data_typeMethod · 0.45
maxMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…