Repository navigation
Description
Enhance the logical CastExpr to support struct-aware casting, field-level nullability checks, and schema-aware validation. Once complete, retire CastColumnExpr by updating the adapter to emit the enhanced CastExpr and consolidate all casting logic into one expression type.
Scope
This is a follow-up to #20163. It aims to unify casting behavior across the planner and execution layers through a single enhanced expression.
Tasks
Logical Expression Enhancement:
- Extend
CastExprindatafusion/expr/to support struct field casting - Add field-level nullability and metadata propagation to
CastExpr - Implement schema-aware validation for target types
Physical Planning & Adapter Integration:
- Update physical planner to convert enhanced
CastExpr→ optimized physical cast - Update
PhysicalExprAdapterto emit enhancedCastExprinstead ofCastColumnExpr - Ensure adapter-generated casts are compatible with new
CastExprsemantics
Testing & Documentation:
- Deprecate
CastColumnExpr(or convert to thin wrapper) - Add SQL logic tests for struct casts in standard SQL queries
- Remove or archive
CastColumnExpronce fully transitioned - Update casting documentation to reflect unified behavior
Files/Modules
datafusion/expr/src/expr.rs(CastExpr extension)datafusion/physical-planner/(logical → physical conversion)datafusion/physical-expr-adapter/src/schema_rewriter.rs(adapter integration)datafusion/sqllogictest/test_files/(new SLT tests for struct casting)
Acceptance Criteria
✅ Enhanced CastExpr supports all CastColumnExpr features
✅ Physical planner correctly converts enhanced CastExpr to physical cast
✅ Adapter emits enhanced CastExpr for schema adaptation
✅ CastColumnExpr is deprecated or removed
✅ SQL logic tests validate struct casts work end-to-end
✅ All existing cast tests continue to pass
✅ Code compiles without warnings
Notes
- Proto deferred: Serialization support for enhanced
CastExprandCastColumnExpris deferred to keep this PR focused on logical/physical expression unification. - Design consideration: Ensure enhanced
CastExprdoesn't become too broad; keep logical cast semantics clear while allowing physical optimization.
Future: Clean-Up and Removal
Once this issue is complete and CastExpr has been adopted everywhere:
- Archive or completely remove
CastColumnExpr - Update documentation to guide users on struct casting in SQL
- Consider whether other physical expressions could benefit from similar unification patterns
Activity
Make Physical CastExpr Field-aware and unify cast semantics across ph…
kosiew commentedon Mar 10, 2026
#20814 adds these changes:
Key changes include:
Field-aware CastExpr
cast_type: DataTypefield withtarget_field: FieldRef.new_with_target_fieldconstructor to explicitly construct field-aware casts.new(expr, DataType)constructor as a compatibility shim that creates a canonical field.Return-field and nullability behavior
return_fieldnow returns the fulltarget_field, preserving name, nullability, and metadata.nullable()now derives its result from the resolved target field rather than the input expression.Struct cast validation improvements
Shared cast property logic
cast_expr_properties,is_order_preserving_cast_family) for determining ordering preservation.CastExprandCastColumnExprto avoid duplicated implementations.Schema rewriter improvements
resolve_physical_column.Ordering equivalence simplification
substitute_cast_like_orderinghelper to unify handling ofCastExprandCastColumnExprin ordering equivalence analysis.Make Physical CastExpr Field-aware and unify cast semantics across ph…
Preserve logical cast field semantics during physical lowering with f…
Migrate PhysicalExprAdapter to unified CastExpr and remove CastColumn…
Unify cast handling by removing `CastColumnExpr` branches in pruning …
Remove CastColumnExpr and custom_file_casts example; unify on field-a…
Remove CastColumnExpr and custom_file_casts example; unify on field-a…
Preserve logical cast field semantics during physical lowering with f…
Migrate PhysicalExprAdapter to unified CastExpr and remove CastColumn…
Unify cast handling by removing `CastColumnExpr` branches in pruning …
Remove CastColumnExpr and custom_file_casts example; unify on field-a…