Copilot commented on code in PR #26150:
URL: https://github.com/apache/datafusion/pull/26150#discussion_r4227070658


##########
datafusion/expr/src/utils.rs:
##########
@@ -1020,6 +1020,20 @@ pub(crate) fn find_columns_referenced_by_expr(e: &Expr) 
-> Vec<Column> {
     exprs
 }
 
+/// Returns the index of the `schema` field that `expr` passes through
+/// unchanged, or `None` if `expr` computes a new value.
+///
+/// Only a column reference (possibly aliased) passes a field through. Use this
+/// instead of comparing [`Expr::schema_name`] with field names: different
+/// expressions can have the same name, e.g. `CAST(t.a AS INT)` is named `t.a`.
+pub fn passthrough_field_index(expr: &Expr, schema: &DFSchema) -> 
Option<usize> {
+    match expr {
+        Expr::Column(col) => schema.maybe_index_of_column(col),

Review Comment:
   `maybe_index_of_column` silently picks the first match for an unqualified 
column, unlike normal expression resolution, which rejects ambiguous references 
(or prefers the sole unqualified field). For a schema containing `a.id` and 
`b.id`, this reports `col("id")` as passing through `a.id`; callers can then 
apply that field's dependency and prune keys incorrectly. Resolve the column 
with the ambiguity-aware `qualified_field_from_column` first and return `None` 
when resolution fails.



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