Kevin-Li-2025 opened a new pull request, #23225:
URL: https://github.com/apache/datafusion/pull/23225
## What changed
Fixes #23045 by making `type_union_resolution` use the union-context
numeric/string coercion rule instead of the comparison-context rule.
This means union-resolution contexts such as `COALESCE` prefer a string type
when combining numeric and string inputs. That avoids inserting casts like
`CAST('' AS Int64)` for `coalesce(1, '')`, because arbitrary strings are not
guaranteed to parse as numbers.
## Why
`type_union_coercion` already documents and tests this distinction:
- comparison contexts prefer numeric semantics for numeric/string pairs
- union contexts prefer string semantics because every number can be
represented as text, but not every string can be represented as a number
`type_union_resolution` was still using `string_numeric_coercion`, which is
the comparison-style numeric preference. `COALESCE` calls
`try_type_union_resolution`, so `coalesce(1, '')` was typed as `Int64`.
## Testing
```text
cargo test -p datafusion-expr-common type_union
cargo test -p datafusion-expr-common string_numeric_coercion
cargo test -p datafusion-sqllogictest --test sqllogictests --
test_files/coalesce.slt
cargo fmt --all --check
git diff --check
```
--
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]