jayzhan211 commented on issue #10424: URL: https://github.com/apache/datafusion/issues/10424#issuecomment-2105427649
> ```sql > select array_slice(column1, -1, 2, 1) from data3; > ``` I think there are two issues here, one is the panic issue in `datafusion-cli` and another one is the API design for `Expr`. 1. `array_slice` panic ``` query ? select array_slice([1, 2, 3], 1, 2, 1); ---- [1, 2] query ? select array_slice([1, 2, 3], -1, 2, 1); ---- PANIC! ``` The reason for panic in the second command is due to the bug in `array_slice` https://github.com/apache/datafusion/blob/933b430839022aaba2c8d8d11d49b3a4ed7af361/datafusion/functions-array/src/extract.rs#L420-L425 And, we need and will fix this. Another issue is that given the current API constraint of `Expr`, we can not provide only 3 arguments. There are many different approaches like giving `vec`, or introducing another function or your proposal ```rust #[doc = "returns a slice of the array."] pub fn array_slice(array: Expr, begin: Expr, end: Expr, stride: Option<Expr>) -> Expr { if let Some(stride) = stride { Expr::ScalarFunction(ScalarFunction::new_udf( array_slice_udf(), vec![array, begin, end, stride], )) } else { Expr::ScalarFunction(ScalarFunction::new_udf( array_slice_udf(), vec![array, begin, end], )) } } ``` I think this is more a user experience problem, how should we design it is discussable. ```rust #[doc = "returns a slice of the array."] pub fn array_slice(array: Expr, begin: Expr, end: Expr, stride: Option<Expr>) -> Expr { if let Some(stride) = stride { Expr::ScalarFunction(ScalarFunction::new_udf( array_slice_udf(), vec![array, begin, end, stride], )) } else { Expr::ScalarFunction(ScalarFunction::new_udf( array_slice_udf(), vec![array, begin, end], )) } } ``` Given the design here, we still need to provide 4 args, where you provide `None` to `stride` if you expect stride with 1. TLDR: The panic issue should be fixed not by redesigning the Expr API, but by fixing the internal array slice code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org