Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when use user field in where caluse #14141

Open
haohuaijin opened this issue Jan 16, 2025 · 5 comments
Open

Error when use user field in where caluse #14141

haohuaijin opened this issue Jan 16, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@haohuaijin
Copy link
Contributor

haohuaijin commented Jan 16, 2025

Describe the bug

DataFusion CLI v44.0.0
> create table t(a int, b int, user text) as values (1,2,'test'), (2,3,null);
0 row(s) fetched.
Elapsed 0.051 seconds.

> select * from t;
+---+---+------+
| a | b | user |
+---+---+------+
| 1 | 2 | test |
| 2 | 3 |      |
+---+---+------+
2 row(s) fetched.
Elapsed 0.006 seconds.

> select * from t where user = 'test';
Error during planning: Invalid function 'user'.
Did you mean 'upper'?

To Reproduce

like above

Expected behavior

this query can run success

Additional context

test in datafusion v44.0.0, v43.0.0 and current main, both reported error
not sure if it is a bug or user is a keyword, but i also check in duckdb, it work

D create table t(a int, b int, user text); insert into t values (1,2,'test'), (2,3,null);
D select * from t where user = 'test';
┌───────┬───────┬─────────┐
│   a   │   b   │  user   │
│ int32 │ int32 │ varchar │
├───────┼───────┼─────────┤
│     1 │     2 │ test    │
└───────┴───────┴─────────┘
D
@chenkovsky
Copy link

it seems that it's sqlparser parsing error. I created an issue apache/datafusion-sqlparser-rs#1658

@alamb
Copy link
Contributor

alamb commented Jan 16, 2025

I think you can work around it by enclosing user in double quotes:

select * from t where "user" = 'test';

@chenkovsky
Copy link

I try to make genericdialect more customizable, but it seems that it maybe not a good idea. ಥ_ಥ

@alamb
Copy link
Contributor

alamb commented Jan 17, 2025

I try to make genericdialect more customizable, but it seems that it maybe not a good idea. ಥ_ಥ

Note there is:
https://datafusion.apache.org/user-guide/configs.html

That might be useful:

datafusion.sql_parser.dialect generic Configure the SQL dialect used by DataFusion’s parser; supported values include: Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, MsSQL, ClickHouse, BigQuery, and Ansi.

@chenkovsky
Copy link

I try to make genericdialect more customizable, but it seems that it maybe not a good idea. ಥ_ಥ

Note there is: https://datafusion.apache.org/user-guide/configs.html

That might be useful:

datafusion.sql_parser.dialect generic Configure the SQL dialect used by DataFusion’s parser; supported values include: Generic, MySQL, PostgreSQL, Hive, SQLite, Snowflake, Redshift, MsSQL, ClickHouse, BigQuery, and Ansi.

at the beginning, I want to implement a dialect which is similar to generic, but it seems that datafusion sql parser cannot support it easily. because too many dialect_of!. for OOP language, dialect_of! is ok, we can extend generic dialect, but for rust,dialect_of! may be not a good idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants