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

   ## Which issue does this PR close?
   
   Closes #27235
   
   ## Rationale for this change
   
   When an `UPDATE` or `DELETE` statement contains repeated expressions in its 
`SET` or `WHERE` clauses (such as implicit repeated casts produced by 
`COALESCE(c0, 0)`), the `common_sub_expression_eliminate` optimizer rule 
factors the expression into a projection below, referencing it as 
`__common_expr_N`. When `physical_planner.rs` extracts the assignments or 
filter predicates for the table provider, these column references cause a 
schema error because the synthetic fields do not exist in the base table schema.
   
   ## What changes are included in this PR?
   
   In `datafusion/core/src/physical_planner.rs`, added a helper function 
`inline_projected_columns`. It walks down the logical plan feeding the DML 
operation (traversing through `Projection`, `Filter`, `Sort`, and `Limit`) and 
substitutes references to projected columns with the unaliased expressions that 
compute them. Both `extract_update_assignments` and `extract_dml_filters` now 
run this substitution before column qualifiers are stripped, ensuring the table 
provider only receives valid base-table expressions.
   
   ## What is the testing strategy for this PR?
   
   - Added regression tests in `dml_update.slt` (repeated expression in SET, in 
SET with a WHERE clause, and in WHERE) and `dml_delete.slt` (repeated 
expression in WHERE). All failed on `main` with `Schema error: No field named 
__common_expr_1/5` and pass with this change.
   - Verified with `cargo test --profile ci -p datafusion-sqllogictest --test 
sqllogictests -- dml_update dml_delete`.
   - Clean run on `cargo fmt` and `cargo clippy`.
   
   ## Are there any user-facing changes?
   
   No breaking API changes. Valid DML statements containing repeated 
expressions now execute successfully.


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