Commit a13c23d
authored
Remove CastColumnExpr and custom_file_casts example; unify on field-aware CastExpr (#21563)
## Which issue does this PR close?
* Closes #20164
---
## Rationale for this change
This PR completes the cast unification effort by removing the remaining
public and example surface of `CastColumnExpr`. Keeping both `CastExpr`
and `CastColumnExpr` introduced duplication in casting logic, increased
maintenance overhead, and made it easier for downstream code to
reintroduce divergent behavior.
With the introduction of field-aware `CastExpr` (via
`new_with_target_field`), all functionality previously covered by
`CastColumnExpr` can now be expressed through a single, consistent
abstraction. This simplifies the mental model for casting, ensures
consistent behavior across execution paths, and aligns documentation and
examples with the unified design.
Additionally, this change ensures that test coverage and examples
reflect the final architecture, reducing confusion for contributors and
users.
---
## What changes are included in this PR?
* **Removal of `CastColumnExpr`**
* Deleted `datafusion/physical-expr/src/expressions/cast_column.rs`.
* Removed module declaration and public re-export from
`expressions/mod.rs`.
* **Migration to field-aware `CastExpr`**
* Updated code paths to rely exclusively on `CastExpr`.
* Replaced usages of `data_type(&schema)` with
`target_field().data_type()` where appropriate.
* **Example updates**
* Updated `custom_file_casts` example to only handle `CastExpr`.
* Removed branching logic that handled both `CastExpr` and
`CastColumnExpr`.
* Updated CLI usage string to reflect current examples.
* **Test consolidation and improvements**
* Migrated struct, nested struct, and scalar struct cast tests into
`cast.rs`.
* Added comprehensive field-aware cast tests covering:
* Target field metadata preservation
* Nullability semantics
* Struct casting with missing fields
* Nested struct casting
* Struct scalar casting
* **Refactoring and cleanup**
* Renamed helper functions for clarity (e.g., `assert_cast_column` →
`assert_cast_input_column`).
* Simplified adapter logic to operate on a single cast expression type.
* **Documentation updates**
* Added upgrade note documenting removal of `CastColumnExpr` and
migration guidance.
---
## Are these changes tested?
Yes.
* Existing tests were updated to reflect the unified cast model.
* Coverage from `cast_column.rs` was preserved and migrated into
`cast.rs`.
* New tests validate:
* Field-aware `CastExpr` semantics
* Struct and nested struct casting behavior
* Scalar struct casting
* Metadata and nullability propagation
* Adapter and schema rewriting tests were updated and remain green.
---
## Are there any user-facing changes?
Yes.
* **Breaking change**: `CastColumnExpr` has been removed from the public
API.
* Users must migrate to `CastExpr`:
* Use `CastExpr::new_with_target_field(...)` for field-aware casting.
* Access output metadata via `target_field()`.
* Access input expressions via `expr()`.
* Documentation has been updated with migration guidance.
---
## LLM-generated code disclosure
This PR includes LLM-generated code and comments. All LLM-generated
content has been manually reviewed and tested.
---1 parent 41dd942 commit a13c23d
7 files changed
Lines changed: 211 additions & 507 deletions
File tree
- datafusion-examples/examples/custom_data_source
- datafusion
- physical-expr-adapter/src
- physical-expr/src/expressions
- docs/source/library-user-guide/upgrading
Lines changed: 14 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
142 | | - | |
| 143 | + | |
143 | 144 | | |
144 | 145 | | |
145 | 146 | | |
| |||
167 | 168 | | |
168 | 169 | | |
169 | 170 | | |
170 | | - | |
171 | | - | |
| 171 | + | |
| 172 | + | |
172 | 173 | | |
173 | 174 | | |
174 | 175 | | |
| |||
177 | 178 | | |
178 | 179 | | |
179 | 180 | | |
180 | | - | |
| 181 | + | |
| 182 | + | |
181 | 183 | | |
182 | | - | |
183 | | - | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
184 | 187 | | |
185 | 188 | | |
186 | 189 | | |
187 | 190 | | |
188 | | - | |
| 191 | + | |
189 | 192 | | |
190 | 193 | | |
191 | 194 | | |
192 | 195 | | |
193 | 196 | | |
194 | 197 | | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | 198 | | |
209 | 199 | | |
210 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
644 | 644 | | |
645 | 645 | | |
646 | 646 | | |
647 | | - | |
| 647 | + | |
648 | 648 | | |
649 | 649 | | |
650 | 650 | | |
| |||
771 | 771 | | |
772 | 772 | | |
773 | 773 | | |
774 | | - | |
| 774 | + | |
775 | 775 | | |
776 | 776 | | |
777 | 777 | | |
| |||
1672 | 1672 | | |
1673 | 1673 | | |
1674 | 1674 | | |
1675 | | - | |
| 1675 | + | |
1676 | 1676 | | |
1677 | 1677 | | |
1678 | 1678 | | |
| |||
1692 | 1692 | | |
1693 | 1693 | | |
1694 | 1694 | | |
1695 | | - | |
| 1695 | + | |
1696 | 1696 | | |
1697 | 1697 | | |
1698 | 1698 | | |
0 commit comments