adriangb opened a new pull request, #21130: URL: https://github.com/apache/datafusion/pull/21130
## Which issue does this PR close? N/A - new feature ## Rationale for this change `arrow_cast(expr, 'DataType')` casts to Arrow data types specified as strings but errors on failure. `try_cast(expr AS type)` returns NULL on failure but only works with SQL types. There's currently no way to attempt a cast to a specific Arrow type and get NULL on failure instead of an error. ## What changes are included in this PR? Adds a new `arrow_try_cast(expression, datatype)` scalar function that combines the behavior of `arrow_cast` and `try_cast`: - Accepts Arrow data type strings (like `arrow_cast`) - Returns NULL on cast failure instead of erroring (like `try_cast`) Implementation details: - Reuses `arrow_cast`'s `data_type_from_args` helper (made `pub(crate)`) - Simplifies to `Expr::TryCast` during optimization (vs `Expr::Cast` for `arrow_cast`) - Registered alongside existing core functions ## Are these changes tested? Yes — new sqllogictest file `arrow_try_cast.slt` covering: - Successful casts (Int64, Float64, LargeUtf8, Dictionary) - Failed cast returning NULL - Same-type passthrough - NULL input - Invalid type string errors - Multiple casts in one query ## Are there any user-facing changes? New `arrow_try_cast` SQL function available. 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- 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]
