adriangb commented on code in PR #25964:
URL: https://github.com/apache/datafusion/pull/25964#discussion_r4299219932


##########
datafusion/functions/src/core/nvl.rs:
##########
@@ -140,6 +159,23 @@ impl ScalarUDFImpl for NVLFunc {
         self.coalesce.short_circuits()
     }
 
+    fn coerce_types(&self, arg_types: &[DataType]) -> Result<Vec<DataType>> {
+        if arg_types.len() != 2 {
+            return exec_err!(
+                "nvl expects exactly two arguments, but received {}",
+                arg_types.len()
+            );
+        }
+        let listed = arg_types
+            .iter()
+            .all(|t| t.is_null() || SUPPORTED_NVL_TYPES.contains(t));
+        if !listed && let Ok(coerced) = self.coalesce.coerce_types(arg_types) {

Review Comment:
   The rule now depends on *which* types are in the call, so the result is not 
always the same as `coalesce`:
   
   - `nvl(Int8, UInt64)` → `Float32` (old path), but `nvl(Int8, 
Decimal128(5,2))` → decimal (coalesce path).
   - `nvl(1, false)` → `Utf8View`, but `coalesce(1, false)` is an error.
   
   This keeps every query that plans today, which is good. But it adds a second 
rule to maintain. An alternative is to use only the coalesce coercion and 
accept the small breaking change (update the `IFNULL(column1, false)` case in 
`expr.slt`).



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