Attempts the scalar-needle fast path for `array_positions`.
(args: &[ColumnarValue])
| 431 | |
| 432 | /// Attempts the scalar-needle fast path for `array_positions`. |
| 433 | fn try_array_positions_scalar(args: &[ColumnarValue]) -> Result<Option<ColumnarValue>> { |
| 434 | let [haystack_arg, needle_arg] = take_function_args("array_positions", args)?; |
| 435 | |
| 436 | let scalar_needle = match needle_arg { |
| 437 | ColumnarValue::Scalar(s) => s, |
| 438 | ColumnarValue::Array(_) => return Ok(None), |
| 439 | }; |
| 440 | |
| 441 | // `not_distinct` doesn't support nested types (List, Struct, etc.), |
| 442 | // so fall back to the per-row path for those. |
| 443 | if scalar_needle.data_type().is_nested() { |
| 444 | return Ok(None); |
| 445 | } |
| 446 | |
| 447 | let (num_rows, all_inputs_scalar) = match haystack_arg { |
| 448 | ColumnarValue::Array(a) => (a.len(), false), |
| 449 | ColumnarValue::Scalar(_) => (1, true), |
| 450 | }; |
| 451 | |
| 452 | let needle = scalar_needle.to_array_of_size(1)?; |
| 453 | let haystack = haystack_arg.to_array(num_rows)?; |
| 454 | |
| 455 | let result = match haystack.data_type() { |
| 456 | List(_) => { |
| 457 | let list = as_list_array(&haystack)?; |
| 458 | array_positions_scalar::<i32>(list, &needle) |
| 459 | } |
| 460 | LargeList(_) => { |
| 461 | let list = as_large_list_array(&haystack)?; |
| 462 | array_positions_scalar::<i64>(list, &needle) |
| 463 | } |
| 464 | t => exec_err!("array_positions does not support type '{t}'"), |
| 465 | }?; |
| 466 | |
| 467 | if all_inputs_scalar { |
| 468 | Ok(Some(ColumnarValue::Scalar(ScalarValue::try_from_array( |
| 469 | &result, 0, |
| 470 | )?))) |
| 471 | } else { |
| 472 | Ok(Some(ColumnarValue::Array(result))) |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | fn array_positions_inner(args: &[ArrayRef]) -> Result<ArrayRef> { |
| 477 | let [haystack, needle] = take_function_args("array_positions", args)?; |
no test coverage detected
searching dependent graphs…