jayzhan211 commented on code in PR #13756:
URL: https://github.com/apache/datafusion/pull/13756#discussion_r1887765061
##########
datafusion/functions-nested/src/extract.rs:
##########
@@ -993,3 +993,84 @@ where
let data = mutable.freeze();
Ok(arrow::array::make_array(data))
}
+
+#[cfg(test)]
+mod tests {
+ use super::array_element_udf;
+ use arrow_schema::{DataType, Field};
+ use datafusion_common::{Column, DFSchema, ScalarValue};
+ use datafusion_expr::expr::ScalarFunction;
+ use datafusion_expr::{cast, Expr, ExprSchemable};
+ use std::collections::HashMap;
+
+ #[test]
+ fn test_array_element_return_type() {
+ let complex_type = DataType::FixedSizeList(
Review Comment:
> the function arguments should already be of the right coerced type
I don't think this is true because we allow any data types as function's
input, and we d the type check or coercion for them.
> I don't know the context of why we needed to apply coercion rules in the
first place
The reason is because we can't guarantee the input is already coerced.
To get the `return_type` of the function, for any given inputs, we check
whether the length is correct, types are matched otherwise coerce if possible.
Then we decide the return type based on the coerced types. If we move
`coercion` out of `get_type`, it means we can't handle function's input that do
implicit casting. For example, like `select abs('1')`, where should we coerce
string to float or int as the function's input?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]