datafusion
datafusion copied to clipboard
Trailing comma output misleading error message
Describe the bug
Putting a trailing comma after the last column/expression within a select statement produces a misleading error message.
To Reproduce
When running the following:
create table my_table as (
select 'Alice' as name, 42 as age
union all
select 'Bob' as name, 1337 as age
);
select
name,
age,
from
my_table
We got the following error message:
Schema error: No field named name.
Expected behavior
Either:
- Accepting trailing comma
- Have an informative error message
Additional context
It took me a while to figure out the issue so I though that it might be helpful to improve on this.
In this case, sqlparser-rs interprets from
as a column name, and my_table
is recognized as the alias of the from
column. Not sure whether we need to solve this problem in sqlparser-rs or in DataFusion. In some databases, from
as a keyword cannot be used as a column name.
Thanks Looks lik
looks like there is a PR upstream to fix this: https://github.com/sqlparser-rs/sqlparser-rs/pull/1212 - I'll try and review it shortly
Thanks for the issue @alexandreyc.
https://github.com/sqlparser-rs/sqlparser-rs/pull/1212 is merged.
The new error message is:
Error during parsing: ParserError("Expected an expression, found: from at Line: 11, Column 5")
However, it will be several weeks till it arrives to DF, since we'll have to wait for the new release of sqlparser, sqlparser version upgrade in DF, and then the new release of DF.