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 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 determine the return type of a function for a given set of inputs, we 
follow these steps:
   
   1. Input Validation: Check if the number of inputs is correct and whether 
their types match the expected types.
   2. Type Coercion: If the input types don't match exactly, attempt to coerce 
them into compatible types.
   3. Return Type Decision: Once coercion is complete (if applicable), decide 
the return type based on the resulting input types.
   
   That is why we have coercion in `get_type` for `return_type`. We can move 
out the coercion in `get_type` to `ScalarFunction::new_udf`



-- 
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

Reply via email to