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

Function array_slice_inner

datafusion/functions-nested/src/extract.rs:417–452  ·  view source on GitHub ↗

array_slice SQL function We follow the behavior of array_slice in DuckDB Note that array_slice is 1-indexed. And there are two additional arguments `from` and `to` in array_slice. > array_slice(array, from, to) Positive index is treated as the index from the start of the array. If the `from` index is smaller than 1, it is treated as 1. If the `to` index is larger than the length of the array, i

(args: &[ArrayRef])

Source from the content-addressed store, hash-verified

415///
416/// See test cases in `array.slt` for more details.
417fn array_slice_inner(args: &[ArrayRef]) -> Result<ArrayRef> {
418 let args_len = args.len();
419 if args_len != 3 && args_len != 4 {
420 return exec_err!("array_slice needs three or four arguments");
421 }
422
423 let stride = if args_len == 4 {
424 Some(as_int64_array(&args[3])?)
425 } else {
426 None
427 };
428
429 let from_array = as_int64_array(&args[1])?;
430 let to_array = as_int64_array(&args[2])?;
431
432 let array_data_type = args[0].data_type();
433 match array_data_type {
434 List(_) => {
435 let array = as_list_array(&args[0])?;
436 general_array_slice::<i32>(array, from_array, to_array, stride)
437 }
438 LargeList(_) => {
439 let array = as_large_list_array(&args[0])?;
440 general_array_slice::<i64>(array, from_array, to_array, stride)
441 }
442 ListView(_) => {
443 let array = as_list_view_array(&args[0])?;
444 general_list_view_array_slice::<i32>(array, from_array, to_array, stride)
445 }
446 LargeListView(_) => {
447 let array = as_large_list_view_array(&args[0])?;
448 general_list_view_array_slice::<i64>(array, from_array, to_array, stride)
449 }
450 _ => exec_err!("array_slice does not support type: {}", array_data_type),
451 }
452}
453
454fn adjusted_from_index<O: OffsetSizeTrait>(index: i64, len: O) -> Result<Option<O>>
455where

Callers

nothing calls this directly

Calls 7

as_int64_arrayFunction · 0.85
as_list_arrayFunction · 0.85
as_large_list_arrayFunction · 0.85
as_list_view_arrayFunction · 0.85
as_large_list_view_arrayFunction · 0.85
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…