Converts a collection of function arguments into a fixed-size array of length N producing a reasonable error message in case of unexpected number of arguments. # Example ``` # use datafusion_common::Result; # use datafusion_common::utils::take_function_args; # use datafusion_common::ScalarValue; fn my_function(args: &[ScalarValue]) -> Result<()> { // function expects 2 args, so create a 2-element
(
function_name: &str,
args: impl IntoIterator<Item = T>,
)
| 1051 | /// my_function(&args).unwrap(); |
| 1052 | /// ``` |
| 1053 | pub fn take_function_args<const N: usize, T>( |
| 1054 | function_name: &str, |
| 1055 | args: impl IntoIterator<Item = T>, |
| 1056 | ) -> Result<[T; N]> { |
| 1057 | let args = args.into_iter().collect::<Vec<_>>(); |
| 1058 | args.try_into().map_err(|v: Vec<T>| { |
| 1059 | _exec_datafusion_err!( |
| 1060 | "{} function requires {} {}, got {}", |
| 1061 | function_name, |
| 1062 | N, |
| 1063 | if N == 1 { "argument" } else { "arguments" }, |
| 1064 | v.len() |
| 1065 | ) |
| 1066 | }) |
| 1067 | } |
| 1068 | |
| 1069 | /// Returns the inner values of a list, or an error otherwise |
| 1070 | /// For [`ListArray`] and [`LargeListArray`], if it's sliced, it returns a |
searching dependent graphs…