v28k opened a new issue, #27235: URL: https://github.com/apache/datafusion/issues/27235
### Describe the bug An `UPDATE` or `DELETE` on an in-memory table fails at planning time with a schema error regarding an internal column when its SET expressions or WHERE clause contain the same expression more than once (for example, `COALESCE(c0, 0)` on an `INT` column, where the column is coerced/cast to `Int64` twice to match the integer literal): UPDATE operation on table 't' caused by Schema error: No field named __common_expr_1. Valid fields are c0, c1. Common subexpression elimination moves the repeated expression into an underlying projection below the UPDATE assignment projection (or below the Filter node). When the physical planner extracts the assignments (`extract_update_assignments`) and filters (`extract_dml_filters`) and hands them to the table provider, the provider evaluates them directly against the table's schema, where `__common_expr_1` does not exist. ### To Reproduce CREATE TABLE t (c0 INT, c1 VARCHAR); INSERT INTO t VALUES (1, 'a'), (NULL, 'b'); UPDATE t SET c0 = COALESCE(c0, 0); -- Schema error: No field named __common_expr_1 UPDATE t SET c1 = 'z' WHERE COALESCE(c0, 0) > 0 AND COALESCE(c0, 0) < 5; -- Schema error: No field named __common_expr_N DELETE FROM t WHERE COALESCE(c0, 0) > 0 AND COALESCE(c0, 0) < 5; -- Schema error: No field named __common_expr_N ### Expected behavior The first UPDATE should update 2 rows (`(1, 'a')`, `(0, 'b')`). The second UPDATE should update 1 row, and the DELETE should delete 1 row. The same expressions execute without error in a `SELECT`. ### Additional context Reproduced on `main` at commit bc86321 (57.0.0-dev) and with datafusion-python 55.0.0. Found via an automated SQL fuzzer comparing execution plans. ### Willingness to contribute I plan to contribute a fix for this bug independently -- 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]
