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


##########
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:
   I looked into this a bit. The PR fixes decimals, timestamps and dates, but 
the pairs that keep nvl's old rule still lose data: `nvl(Int64, UInt64)` → 
`Float32`, where `coalesce` gives an exact `Decimal128(20,0)` (and DuckDB gives 
HUGEINT). Using only the coalesce rules seems better to me:
   1. It's more correct.
   2. It matches DuckDB and Postgres better. I can share a table if that helps.
   3. It's less code and less complexity.
   
   The cost is that mixed int/bool calls such as `IFNULL(int_col, false)` stop 
planning. Currently they return a string (`'1'` / `'false'`). Postgres and our 
own `coalesce` reject them. I think that's an acceptable break, with an 
upgrade-guide note. WDYT @alamb?



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