Skip to content

minor: Improve error message for invalid column expression in SELECT statement#22486

Open
2010YOUY01 wants to merge 6 commits into
apache:mainfrom
2010YOUY01:col-did-you-mean
Open

minor: Improve error message for invalid column expression in SELECT statement#22486
2010YOUY01 wants to merge 6 commits into
apache:mainfrom
2010YOUY01:col-did-you-mean

Conversation

@2010YOUY01
Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • Closes #.

Rationale for this change

User friendly 'did you mean' error message is missing for some cases, this PR fixes it.

Demo in datafusion-cli

-- Before
> create external table hits
stored as parquet
location '/Users/yongting/Code/datafusion/benchmarks/data/hits_partitioned';
0 row(s) fetched.
Elapsed 0.056 seconds.

> select url+1 from hits;
Schema error: No field named url. Valid fields are hits."WatchID", hits."JavaEnable", hits."Title", hits."GoodEvent", hits."EventTime", hits."EventDate", hits."CounterID", hits."ClientIP", hits."RegionID", hits."UserID", hits."CounterClass",
...
-- PR
> select url from hits;
Schema error: No field named url. Did you mean 'hits."URL"'?
Column names are case sensitive. You can use double quotes to refer to the hits."URL" column or set the datafusion.sql_parser.enable_ident_normalization configuration.
Valid fields are hits."WatchID", hits."JavaEnable", hits."Title", hits."GoodEvent", hits."EventTime", hits."EventDate", hits."CounterID", hits."ClientIP", hits."RegionID", hits."UserID", hits."CounterClass", hits."OS", hits."UserAgent", hits."URL", hits."Referer", hits."IsRefresh", hits."RefererCategoryID", hits."RefererRegionID", hits."URLCategoryID", hits."URLRegionID",
...

What changes are included in this PR?

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions Bot added sql SQL Planner logical-expr Logical plan and expressions core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) common Related to common crate labels May 24, 2026
// lookup with unqualified name "t1.c0"
let err = schema.index_of_column(&col).unwrap_err();
let expected = "Schema error: No field named \"t1.c0\". \
Column names are case sensitive. \
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.

Now this case sensitive hint only shows up, if the input expr has some case-insensitive match.

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

Labels

common Related to common crate core Core DataFusion crate logical-expr Logical plan and expressions sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant