kosiew opened a new pull request, #20485:
URL: https://github.com/apache/datafusion/pull/20485

   ## Which issue does this PR close?
   
   * 
[Comment](https://github.com/apache/datafusion/pull/20202#discussion_r2804840366)
 on #20202
   
   ## Rationale for this change
   
   When adapting physical expressions across differing logical/physical 
schemas, relying on `Column::index()` can be incorrect if the physical schema 
column ordering differs from the logical plan (or if a `Column` is constructed 
with an index that doesn’t match the current physical schema). This can lead to 
looking up the wrong physical field, causing incorrect casts, type mismatches, 
or runtime failures.
   
   This change ensures the adapter always resolves the physical field using the 
column **name** against the physical file schema, making expression rewriting 
robust to schema reordering and avoiding subtle bugs where an index points at 
an unrelated column.
   
   ## What changes are included in this PR?
   
   * Updated `create_cast_column_expr` to resolve the physical field via 
`physical_file_schema.index_of(column.name())` instead of `column.index()`.
   * Added a regression test that deliberately supplies a mismatched `Column` 
index and asserts the rewriter still selects the correct physical field by name 
and produces the expected `CastColumnExpr`.
   
   ## Are these changes tested?
   
   Yes.
   
   * Added `test_create_cast_column_expr_uses_name_lookup_not_column_index` 
which covers the scenario where physical and logical schemas have different 
column orders and the provided `Column` index is incorrect.
   
   ## Are there any user-facing changes?
   
   No direct user-facing changes.
   
   This is an internal correctness fix that improves robustness of physical 
expression adaptation when schema ordering differs between logical and physical 
plans.
   
   <!--
   If there are any breaking changes to public APIs, please add the `api 
change` label.
   -->
   


-- 
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]

Reply via email to