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])
| 415 | /// |
| 416 | /// See test cases in `array.slt` for more details. |
| 417 | fn 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 | |
| 454 | fn adjusted_from_index<O: OffsetSizeTrait>(index: i64, len: O) -> Result<Option<O>> |
| 455 | where |
nothing calls this directly
no test coverage detected
searching dependent graphs…