mesejo commented on code in PR #12308:
URL: https://github.com/apache/datafusion/pull/12308#discussion_r1744452513


##########
datafusion/functions/src/core/coalesce.rs:
##########
@@ -60,12 +60,16 @@ impl ScalarUDFImpl for CoalesceFunc {
     }
 
     fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
-        Ok(arg_types[0].clone())
+        Ok(arg_types
+            .iter()
+            .find_or_first(|d| !d.is_null())
+            .unwrap()
+            .clone())
     }
 
-    // If all the element in coalesce is non-null, the result is non-null
+    // If all the elements in coalesce are non-null, the result is non-null
     fn is_nullable(&self, args: &[Expr], schema: &dyn ExprSchema) -> bool {
-        args.iter().any(|e| e.nullable(schema).ok().unwrap_or(true))
+        args.iter().all(|e| e.nullable(schema).ok().unwrap_or(true))

Review Comment:
   I pushed that change to the PR, but it caused some test failures, for 
example the statement:
   ```sql
   SELECT encode(12, 'hex')
   ```
   
   Doesn't produce the error:
   
   > query error DataFusion error: Error during planning: The encode function 
can only accept utf8 or binary\.
   
   The source seems to be this line in the function `coerced_from`:
   
https://github.com/apache/datafusion/blob/91b1d2bfe8f603df94e846b91d8475a0af2e5240/datafusion/expr/src/type_coercion/functions.rs#L681-L682
   
   It specifies that any `DataType` can be coerced into a `Utf8`.
   
   So, what is the best approach to move forward, @jayzhan211?  



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

Reply via email to