Commit a32c4b2
fix: preserve source field metadata in TryCast expressions (#21390)
## Which issue does this PR close?
N/A — discovered while investigating metadata propagation through cast
expressions in #21322
## Rationale for this change
`Expr::Cast` preserves the source field's metadata through a dedicated
`to_field` handler in `expr_schema.rs`, but `Expr::TryCast` fell through
to the default case which creates a `Field::new(...)` without any
metadata. This caused source column metadata to be silently dropped when
using `TRY_CAST`.
## What changes are included in this PR?
- Added a dedicated `to_field` handler for `Expr::TryCast` in
`expr_schema.rs` that preserves source field metadata (matching
`Expr::Cast` behavior), while keeping TryCast's always-nullable
semantics.
- Added SLT tests in `metadata.slt` verifying metadata preservation
through `TRY_CAST` on both timestamp and integer columns.
## Are these changes tested?
Yes — new sqllogictest cases in `metadata.slt` using `arrow_metadata()`
to verify metadata is preserved through `TRY_CAST`.
## Are there any user-facing changes?
`TRY_CAST` now preserves source field metadata, consistent with `CAST`
behavior.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 0b8c4c5 commit a32c4b2
File tree
2 files changed
+94
-17
lines changed- datafusion
- expr/src
- sqllogictest/test_files
2 files changed
+94
-17
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
68 | 86 | | |
69 | 87 | | |
70 | 88 | | |
| |||
553 | 571 | | |
554 | 572 | | |
555 | 573 | | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
567 | | - | |
568 | | - | |
569 | | - | |
570 | | - | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
571 | 577 | | |
572 | | - | |
| 578 | + | |
573 | 579 | | |
574 | 580 | | |
575 | 581 | | |
576 | 582 | | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
577 | 588 | | |
578 | 589 | | |
579 | 590 | | |
580 | 591 | | |
581 | 592 | | |
582 | | - | |
583 | 593 | | |
584 | 594 | | |
585 | 595 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
220 | 220 | | |
221 | 221 | | |
222 | 222 | | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
223 | 251 | | |
224 | 252 | | |
225 | 253 | | |
| |||
347 | 375 | | |
348 | 376 | | |
349 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
350 | 417 | | |
351 | 418 | | |
0 commit comments