Repository navigation
Commit 4f7ce26
authored
feat: include source field context in cast errors (apache#24920)
## Which issue does this PR close?
- Closes apache#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 apache#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.1 parent a5a525e commit 4f7ce26
2 files changed
Lines changed: 58 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
333 | | - | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
334 | 349 | | |
335 | 350 | | |
336 | 351 | | |
| |||
769 | 784 | | |
770 | 785 | | |
771 | 786 | | |
772 | | - | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
773 | 792 | | |
774 | 793 | | |
775 | 794 | | |
| |||
1088 | 1107 | | |
1089 | 1108 | | |
1090 | 1109 | | |
1091 | | - | |
| 1110 | + | |
1092 | 1111 | | |
1093 | 1112 | | |
1094 | 1113 | | |
1095 | 1114 | | |
1096 | 1115 | | |
1097 | 1116 | | |
1098 | | - | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
1102 | | - | |
1103 | | - | |
1104 | | - | |
1105 | | - | |
1106 | | - | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
1107 | 1124 | | |
1108 | 1125 | | |
1109 | 1126 | | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
1110 | 1155 | | |
1111 | 1156 | | |
1112 | 1157 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
0 commit comments