CuteChuanChuan opened a new pull request, #26498: URL: https://github.com/apache/datafusion/pull/26498
## Which issue does this PR close? - Closes #26024. ## Rationale for this change The result type of `nvl2(x, a, b)` depended on the type of `x`, even though `x` is only checked for NULL. This caused decimal results to be widened (e.g. `Decimal128(22, 2)`) or turned into strings, and made timestamp results fail during planning or optimization. The equivalent `CASE WHEN x IS NOT NULL THEN a ELSE b END` worked in all of these cases. ## What changes are included in this PR? - `NVL2Func::coerce_types` now finds the common type of `a` and `b` only, using `type_union_coercion` (the same rule `CASE` uses for its THEN/ELSE branches). `x` keeps its original type. - If `a` and `b` have no common type, it now returns a plan error instead of an internal error. ## What is the testing strategy for this PR? Added sqllogictest cases to `nvl2.slt` that cover the reproducers from the issue (decimal with int/float/string tests, timestamp with int/string-literal tests). Each case checks both the value and `arrow_typeof`. ## Are there any user-facing changes? Yes. `nvl2` now returns the same type as the equivalent `CASE` expression. Queries that used to get a widened decimal or `Utf8` result now get the type of `a`/`b`, and the timestamp cases that used to error now work. No public API changes. -- 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]
