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

   ## Which issue does this PR close?
   
   * Part of #19950
   
   ---
   
   ## Rationale for this change
   
   Previously, `UPDATE ... FROM` statements were rejected early in the SQL 
planner, preventing even valid single-target update cases from reaching logical 
planning. This blocked progress toward full support for joined updates and made 
it difficult to incrementally implement the feature.
   
   Additionally, the existing assignment extraction logic stripped column 
qualifiers unconditionally, which caused incorrect expressions when updates 
referenced joined sources (e.g. `SET t1.a = t2.b`).
   
   This PR enables logical planning for `UPDATE ... FROM` and introduces a more 
precise analysis of the input plan so that assignment expressions and filters 
are handled correctly depending on whether joins are present.
   
   ---
   
   ## What changes are included in this PR?
   
   * **Planner enablement**
   
     * Removed the early rejection of `UPDATE ... FROM` in the SQL layer.
     * Logical planner now produces joined update plans (e.g. via `Cross Join` 
+ `Filter`).
   
   * **Fail-closed physical planning**
   
     * Added a guard in the physical planner to reject joined updates (`UPDATE 
... FROM`) until execution support is implemented.
     * Ensures correctness by preventing unsafe execution paths.
   
   * **DML input analysis**
   
     * Introduced `DmlInputAnalysis` to:
   
       * Detect whether the input contains joins
       * Track valid target table references and aliases
     * Added `analyze_dml_input` and `analyze_target_branch` helpers.
   
   * **Filter extraction improvements**
   
     * Reworked filter extraction to use analysis-driven target reference 
tracking.
     * Ensures only predicates relevant to the target table are pushed down.
   
   * **Assignment extraction overhaul**
   
     * Refactored assignment extraction into:
   
       * `find_update_projection`
       * `append_update_assignments`
       * `extract_update_assignments_with_analysis`
     * Preserves qualifiers for joined-source expressions.
     * Strips qualifiers only for single-table updates to maintain provider 
compatibility.
     * Improved identity-assignment detection to respect table references.
   
   * **SQL planning tests**
   
     * Added logical plan tests verifying:
   
       * `UPDATE ... FROM` with joins
       * Alias handling
       * `EXPLAIN UPDATE ... FROM`
   
   * **Physical planner and DML tests**
   
     * Updated tests to assert fail-closed behavior for joined updates.
     * Added coverage for:
   
       * joined assignment preservation (`t2.col`)
       * alias-qualified references
       * same-name column disambiguation
       * self-joins
       * single-table qualifier stripping
   
   ---
   
   ## Are these changes tested?
   
   Yes.
   
   This PR adds and updates comprehensive test coverage across both SQL and 
physical planning layers:
   
   * Logical plan tests confirm that `UPDATE ... FROM` is now accepted and 
produces the expected plan structure.
   * Physical planner tests verify that execution still fails with a clear 
error (`UPDATE ... FROM is not supported`).
   * Unit tests validate assignment extraction behavior for:
   
     * joined sources
     * aliases
     * column name conflicts
     * self-joins
     * single-table updates
   
   These tests ensure both correctness and safe incremental rollout of the 
feature.
   
   ---
   
   ## Are there any user-facing changes?
   
   Yes.
   
   * `UPDATE ... FROM` is no longer rejected during SQL parsing/planning.
   * Users can now run `EXPLAIN UPDATE ... FROM` and inspect logical plans.
   * Execution of such queries still fails with:
   
     ```
     This feature is not implemented: UPDATE ... FROM is not supported
     ```
   
   This provides improved visibility while maintaining safe behavior until full 
execution support is implemented.
   
   ---
   
   ## LLM-generated code disclosure
   
   This PR includes LLM-generated code and comments. All LLM-generated content 
has been manually reviewed and tested.
   


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