You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "kosiew (via GitHub)" <gi...@apache.org> on 2026/02/23 07:44:10 UTC
[PR] Fix physical expr adapter to resolve physical fields by name, not column index [datafusion]
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix physical expr adapter to resolve physical fields by name, not column index [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew merged PR #20485:
URL: https://github.com/apache/datafusion/pull/20485
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [PR] Fix physical expr adapter to resolve physical fields by name, not column index [datafusion]
Posted by "kosiew (via GitHub)" <gi...@apache.org>.
kosiew commented on PR #20485:
URL: https://github.com/apache/datafusion/pull/20485#issuecomment-3951325973
@adriangb ,
In file scans, we can legitimately rewrite expressions between a logical file schema and a physical file schema whose field order differs. So relying on a `Column` index alone is brittle at adaptation boundaries.
This change makes the adapter defensive by resolving the field via `column.name()` against the physical schema at the cast-construction point, instead of trusting `column.index()`. That avoids selecting an unrelated field when an index is stale or mismatched.
--
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: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org