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

   ## Which issue does this PR close?
   
   - Closes #14436.
   
   Continues #20720 by @buraksenn, rebased onto current main.
   
   ## Rationale for this change
   
   When a query repeats a CTE name, or a table name or alias in the same `FROM`
   scope, the error has no source location. For relations it also comes late, as
   `Schema contains duplicate qualified field name`, so users can't easily see
   which two names collide.
   
   ## What changes are included in this PR?
   
   - Duplicate CTE names: attach a `Diagnostic` at the repeated name, with a 
note
     at the first definition.
   - Duplicate relation names in a `FROM` scope (comma-separated entries, JOINs,
     parenthesized joins):
     - Each one adds a non-fatal warning `Diagnostic`
       (`table name "t" specified more than once`, with a note at the first
       definition). There is exactly one warning per duplicate.
     - If planning then fails with `DuplicateQualifiedField` for that name, the
       error gets a `Diagnostic` pointing at both relations. The error message
       text is unchanged.
     - Whether a query plans or fails is unchanged.
   - Names are compared as `TableReference`s that match the planned qualifiers.
     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 can't resolve are skipped.
   
   ## 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 
one
       warning with the right spans. Queries with overlapping columns fail with
       the original message plus an error Diagnostic. Queries with disjoint
       columns and LEFT SEMI joins plan successfully.
     - `test_duplicate_table_name_single_warning_in_multi_entry_from`: one
       warning, not two, 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`: existing expectations 
are
     unchanged. 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?
   
   - New warning `Diagnostic`s for duplicate relation names. Callers read them
     with `SqlToRel::take_warnings`.
   - An error `Diagnostic` is now attached to duplicate CTE and duplicate
     qualified field errors.
   - No breaking changes: the same queries plan or fail as before, with the same
     error messages.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


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