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

Function array_resize_inner

datafusion/functions-nested/src/resize.rs:147–187  ·  view source on GitHub ↗
(arg: &[ArrayRef])

Source from the content-addressed store, hash-verified

145}
146
147fn array_resize_inner(arg: &[ArrayRef]) -> Result<ArrayRef> {
148 if arg.len() < 2 || arg.len() > 3 {
149 return exec_err!("array_resize needs two or three arguments");
150 }
151
152 let array = &arg[0];
153
154 // Checks if entire array is null
155 if array.logical_null_count() == array.len() {
156 let return_type = match array.data_type() {
157 List(field) => List(Arc::clone(field)),
158 LargeList(field) => LargeList(Arc::clone(field)),
159 _ => {
160 return exec_err!(
161 "array_resize does not support type '{:?}'.",
162 array.data_type()
163 );
164 }
165 };
166 return Ok(new_null_array(&return_type, array.len()));
167 }
168
169 let new_len = as_int64_array(&arg[1])?;
170 let new_element = if arg.len() == 3 {
171 Some(Arc::clone(&arg[2]))
172 } else {
173 None
174 };
175
176 match &arg[0].data_type() {
177 List(field) => {
178 let array = as_list_array(&arg[0])?;
179 general_list_resize::<i32>(array, new_len, field, new_element)
180 }
181 LargeList(field) => {
182 let array = as_large_list_array(&arg[0])?;
183 general_list_resize::<i64>(array, new_len, field, new_element)
184 }
185 array_type => exec_err!("array_resize does not support type '{array_type}'."),
186 }
187}
188
189/// array_resize keep the original array and append the default element to the end
190fn general_list_resize<O: OffsetSizeTrait + TryInto<i64>>(

Callers

nothing calls this directly

Calls 6

as_int64_arrayFunction · 0.85
as_list_arrayFunction · 0.85
as_large_list_arrayFunction · 0.85
ListClass · 0.50
lenMethod · 0.45
data_typeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…