Repository navigation
feat: attach Diagnostic to duplicate table name errors - #26202
Open
haochunchang wants to merge 1 commit into
Open
haochunchang wants to merge 1 commit into
haochunchang wants to merge 1 commit into
Conversation
haochunchang
force-pushed
the
worktree-diag-duplicate-table-name
branch
from
October 11, 2026 08:45
dde7d4d to
e1b368b
Compare
haochunchang
marked this pull request as ready for review
October 11, 2026 10:19
Closes apache#14436. Continues apache#20720 by @buraksenn, rebased onto current main. - Duplicate CTE names: attach a Diagnostic pointing at the repeated name, with a note at the first definition. CTE spans are stored in PlannerContext; the public insert_cte/get_cte API is unchanged. - Duplicate relation names in a FROM scope (comma-separated entries, explicit JOINs, and inside parenthesized joins) add a non-fatal warning Diagnostic, `table name "t" specified more than once`, once per duplicate. If planning then fails with DuplicateQualifiedField for that name, an error Diagnostic pointing at both relations is attached. Whether a query plans or fails, and the error message text, are unchanged. - Names are compared as TableReferences that match the planned qualifiers, so schema1.person and schema2.person are distinct, a quoted alias "s.t" does not match s.t, and an unaliased table function foo(..) (qualifier foo()) does not match a table foo. Names the check cannot resolve are skipped and left to normal planning. Co-authored-by: buraksenn <buraksenb@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
haochunchang
force-pushed
the
worktree-diag-duplicate-table-name
branch
from
October 12, 2026 00:10
e1b368b to
e3f6375
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Diagnosticto "duplicate table name" error #14436.Continues #20720 by @buraksenn, rebased onto current main.
Rationale for this change
If a query uses the same name twice in one
FROMclause, DataFusion rejects it, but the error is unhelpful in two ways:What changes are included in this PR?
Diagnosticat the repeated name, with a note at the first definition.FROMscope (comma-separated entries, JOINs, parenthesized joins):Diagnostic. There is exactly 1 warning per duplicate.DuplicateQualifiedFieldfor that name, the error gets aDiagnosticpointing at both relations. The error message text is unchanged.TableReferences that match the planned qualifiers."s.t"does not matchs.t, and an unaliased table functionfoo(..)(qualifierfoo()) does not match a tablefoo. (datafusion/sqllogictest/test_files/join.slt.part)What is the testing strategy for this PR?
datafusion/sql/tests/cases/diagnostic.rs:test_duplicate_cte_name: error Diagnostic spans for duplicate CTEs.test_duplicate_table_name: for each FROM shape, checks that there is 1 warning with the right spans:test_duplicate_table_name_single_warning_in_multi_entry_from: 1 warning, not 2, when a duplicate spans comma-separated entries.test_same_table_name_in_different_scopes: no warning across scopes.datafusion/sqllogictest/test_files/join.slt.part: New cases cover a quoted dotted alias vs a schema-qualified table, and a table function vs a same-named table.Are there any user-facing changes?
Diagnostics for duplicate relation names. Callers read them withSqlToRel::take_warnings.Diagnosticis now attached to duplicate CTE and duplicate qualified field errors.FROM j1 AS t, j2 AS twith disjoint columns) still plan, now with a warning.🤖 Generated with Claude Code and manually edited by @haochunchang .