Skip to content

fix(datafusion): preserve quoted aliases in MERGE statements - #1271

Open
slfan1989 wants to merge 2 commits into
apache:mainfrom
slfan1989:paimon-rust-1269
Open

slfan1989 wants to merge 2 commits into
apache:mainfrom
slfan1989:paimon-rust-1269

Conversation

@slfan1989

Copy link
Copy Markdown
Contributor

Purpose

Linked issue: closes #1269

Fix MERGE statements failing with aliases containing spaces, reserved words, embedded quotes, or case-sensitive names.

Brief change log

  • Preserve aliases as sqlparser Ident values throughout MERGE execution.
  • Retain quoting, escaping, and case when generating SQL and rewriting column qualifiers.
  • Add regression coverage for table and subquery aliases on ordinary and Data Evolution tables.

Tests

  • Confirmed both new regression tests fail before the fix.

API and Format

No.

Documentation

No.

@slfan1989

Copy link
Copy Markdown
Contributor Author

Hi @JingsongLi, @QuakeWang Could you please review this PR when you have time? It fixes quoted alias handling in MERGE statements and adds regression tests. Thanks!

if !can_prune_target_by_source_partitions(partition_keys, t_alias, s_alias, on_expr) {
if !can_prune_target_by_source_partitions(
partition_keys,
&t_alias.value,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: could we retain Ident here and compare aliases using DataFusion’s identifier rules? The downstream eq_ignore_ascii_case conflates target "T" with source "t", treating "t".value = "t".value as a target/source partition equality. I reproduced this on a partitioned CoW table: pruning skips a matching target row, and MERGE inserts instead of updating it. It would be good to handle this here and add a regression test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I’ll preserve Ident in the partition-pruning checks, follow DataFusion’s identifier rules, and add a regression test for case-sensitive aliases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] MERGE fails with quoted table aliases

2 participants