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

   ## Which issue does this PR close?
   
   - Part of #20746.
   - Follow-up to #22988.
   
   ## Rationale for this change
   
   Valid MERGE statements are currently rejected when an aliased target is 
referenced from a correlated subquery, or when a source qualifier matches the 
target table's real name. Rewriting the visible target alias to the catalog 
table name conflates two distinct SQL bindings and can change expression 
meaning.
   
   ## What changes are included in this PR?
   
   - Preserve the MERGE target's SQL-visible qualifier separately from its 
provider identity.
   - Centralize construction of the target-plus-source expression schema across 
SQL planning, analyzer/optimizer passes, physical planning, and programmatic 
plans.
   - Remove qualifier canonicalization and the recursive target-correlation 
guard while retaining lexical shadowing behavior.
   - Serialize the target qualifier in MERGE protobuf plans, with `table_name` 
fallback for payloads written before this field existed.
   - Document the `MergeIntoOp::new` API migration and clarify provider 
handling of residual subqueries.
   - Add coverage for qualifier collisions, quoted and qualified names, 
correlated subquery forms, nested shadowing, lateral scopes, proto round trips, 
and physical column indices.
   
   MERGE has not shipped in a release. New alias-preserving MERGE protobuf 
payloads are not promised to be readable by older DataFusion versions, because 
older readers do not know the target qualifier field. New readers remain able 
to decode existing payloads by falling back to `DmlNode.table_name`.
   
   ## Are these changes tested?
   
   - `cargo fmt --all`
   - `cargo clippy --all-targets --all-features -- -D warnings`
   - `./ci/scripts/doc_prettier_check.sh --write --allow-dirty`
   - `RUST_BACKTRACE=1 cargo test --profile ci --exclude datafusion-examples 
--exclude datafusion-benchmarks --exclude datafusion-cli --workspace --lib 
--tests --bins --features 
avro,json,backtrace,extended_tests,recursive_protection,parquet_encryption`
   
   ## Are there any user-facing changes?
   
   Yes. The two valid MERGE forms described above now plan successfully and 
reach `TableProvider::merge_into`. `MergeIntoOp` is now non-exhaustive and must 
be constructed with `MergeIntoOp::new(target_qualifier, on, clauses)`; the 
55.0.0 upgrade guide documents the migration.


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