Skip to content

Conversation

@Shivfun99
Copy link

What this does

Enhances the SQL planner error message when a referenced table is not found by attaching a clearer diagnostic instead of a generic error.

Why

This improves developer UX by making it easier to understand why a query failed and where the issue occurred in the SQL span.

Changes

  • Wrapped missing-table errors with a structured Diagnostic
  • Preserved existing planner behavior
  • Added better error context for SQL users

Testing

  • Ran cargo test -p datafusion-sql
  • Manually tested missing table scenarios in DataFusion CLI

@github-actions github-actions bot added the sql SQL Planner label Jan 18, 2026
@Jefffrey
Copy link
Contributor

Is there an example of what this improved error looks like compared to the original version?

@Shivfun99
Copy link
Author

Is there an example of what this improved error looks like compared to the original version?

The planner now attaches a structured diagnostic with SQL span context:

Error: table 'userz' not found
┌─ SQL

1 │ SELECT * FROM userz;
│ ^^^^^

= Did you mean: users?

@Jefffrey
Copy link
Contributor

Is there a clear before & after test case to reference here? Best I can tell, this PR essentially only does this:

-format!("table '{}' not found", table_ref)
+format!("table '{}' not found", table_ref.table().to_string())

We already had the diagnostics, so I'm struggling to understand what exactly this PR is trying to fix/improve.

@Shivfun99
Copy link
Author

Is there a clear before & after test case to reference here? Best I can tell, this PR essentially only does this:

-format!("table '{}' not found", table_ref)
+format!("table '{}' not found", table_ref.table().to_string())

We already had the diagnostics, so I'm struggling to understand what exactly this PR is trying to fix/improve.

Thanks for the feedback — that’s fair.

The main intent here is to keep the primary error string aligned with how users write SQL, by using the bare table name (table_ref.table()) rather than the full TableReference display (which can include schema/catalog qualifiers). This makes the error message and any follow-up suggestions easier to read and more consistent with the input query.

To make the improvement explicit, I’m happy to add a small regression test. For example:

Query:
SELECT * FROM userz;

Before:
Error: table 'public.userz' not found

After:
Error: table 'userz' not found
(with the diagnostic span preserved)

If that direction makes sense, I can push a test in datafusion/sql/tests to assert the bare-name behavior.

@Jefffrey
Copy link
Contributor

I'm not sure there is a clear motivating use case to this PR, and I am quite hesitant with it overall given the original PR body is incorrect in what it describes this PR does and only after my review was a comment added to properly describe what this PR does. Was this LLM generated?

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

Labels

sql SQL Planner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants