haohuaijin opened a new pull request, #24920: URL: https://github.com/apache/datafusion/pull/24920
## Which issue does this PR close? - Closes #24919. ## Rationale for this change Runtime cast errors currently identify the invalid value and target type but not the source field. This makes failures difficult to diagnose when a query contains multiple casts or an application processes many fields. Including the source field in the error provides actionable context while retaining the original Arrow error as the cause. ## What changes are included in this PR? This PR adds context to errors returned by `CastExpr::evaluate`: - Resolves the child expression's output field from the input schema when a cast fails. - Reports the source field name and the source and target data types. - Falls back to the physical expression when a field name cannot be resolved. - Preserves the original cast error as the underlying cause. For example, the error now looks like: ```text Failed to cast field 'a' from Utf8View to Int32 caused by Arrow error: Cast error: Cannot cast string '2619.200945' to value of Int32 type ``` ## Are these changes tested? Yes. The existing invalid cast unit test now verifies the complete error, including the source field, source and target data types, and original Arrow error. The following checks pass: ```shell cargo fmt --all cargo test -p datafusion-physical-expr invalid_cast_with_options_error cargo clippy --all-targets --all-features -- -D warnings ``` The behavior was also verified end to end with the DataFusion CLI using the reproduction from #24919. ## Are there any user-facing changes? Yes. Runtime cast error messages now include the source field and source and target data types. The original cast error remains available as the cause. There are 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]
