-
Couldn't load subscription status.
- Fork 1.7k
fix: try to lower plain reserved functions to columns as well #16669
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
Conversation
When a reserved function like `user` is called without parenthesis, it may as well be a column. This works in PostgreSQL for example: ```text psql (17.5 (Debian 17.5-1.pgdg120+1)) Type "help" for help. postgres=# create table t(a int, "user" text); CREATE TABLE postgres=# insert into t values (1, 'foo'); INSERT 0 1 postgres=# select t.user from t; user ------ foo (1 row) postgres=# select user from t; user ---------- postgres (1 row) ``` However sqlparser tries to detect these functions, see apache/datafusion-sqlparser-rs#1909 We now first try to use the respective function and then also consider columns. Fixes apache#14141.
7adc63a to
95805f0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @crepererum -- looks good to me
cc @jonahgao in case you also have time to review
| /// WITHIN GROUP clause, if any | ||
| within_group: Vec<OrderByExpr>, | ||
| /// Was the function called without parenthesis, i.e. could this also be a column reference? | ||
| function_without_paranthesis: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a typo here:
| function_without_paranthesis: bool, | |
| function_without_parenthesis: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
|
Thank you for the review @jonahgao ❤️ |
…#16669) When a reserved function like `user` is called without parenthesis, it may as well be a column. This works in PostgreSQL for example: ```text psql (17.5 (Debian 17.5-1.pgdg120+1)) Type "help" for help. postgres=# create table t(a int, "user" text); CREATE TABLE postgres=# insert into t values (1, 'foo'); INSERT 0 1 postgres=# select t.user from t; user ------ foo (1 row) postgres=# select user from t; user ---------- postgres (1 row) ``` However sqlparser tries to detect these functions, see apache/datafusion-sqlparser-rs#1909 We now first try to use the respective function and then also consider columns. Fixes apache#14141.
…#16669) When a reserved function like `user` is called without parenthesis, it may as well be a column. This works in PostgreSQL for example: ```text psql (17.5 (Debian 17.5-1.pgdg120+1)) Type "help" for help. postgres=# create table t(a int, "user" text); CREATE TABLE postgres=# insert into t values (1, 'foo'); INSERT 0 1 postgres=# select t.user from t; user ------ foo (1 row) postgres=# select user from t; user ---------- postgres (1 row) ``` However sqlparser tries to detect these functions, see apache/datafusion-sqlparser-rs#1909 We now first try to use the respective function and then also consider columns. Fixes apache#14141.
…#16669) When a reserved function like `user` is called without parenthesis, it may as well be a column. This works in PostgreSQL for example: ```text psql (17.5 (Debian 17.5-1.pgdg120+1)) Type "help" for help. postgres=# create table t(a int, "user" text); CREATE TABLE postgres=# insert into t values (1, 'foo'); INSERT 0 1 postgres=# select t.user from t; user ------ foo (1 row) postgres=# select user from t; user ---------- postgres (1 row) ``` However sqlparser tries to detect these functions, see apache/datafusion-sqlparser-rs#1909 We now first try to use the respective function and then also consider columns. Fixes apache#14141.
…#16669) When a reserved function like `user` is called without parenthesis, it may as well be a column. This works in PostgreSQL for example: ```text psql (17.5 (Debian 17.5-1.pgdg120+1)) Type "help" for help. postgres=# create table t(a int, "user" text); CREATE TABLE postgres=# insert into t values (1, 'foo'); INSERT 0 1 postgres=# select t.user from t; user ------ foo (1 row) postgres=# select user from t; user ---------- postgres (1 row) ``` However sqlparser tries to detect these functions, see apache/datafusion-sqlparser-rs#1909 We now first try to use the respective function and then also consider columns. Fixes apache#14141.
…#16669) When a reserved function like `user` is called without parenthesis, it may as well be a column. This works in PostgreSQL for example: ```text psql (17.5 (Debian 17.5-1.pgdg120+1)) Type "help" for help. postgres=# create table t(a int, "user" text); CREATE TABLE postgres=# insert into t values (1, 'foo'); INSERT 0 1 postgres=# select t.user from t; user ------ foo (1 row) postgres=# select user from t; user ---------- postgres (1 row) ``` However sqlparser tries to detect these functions, see apache/datafusion-sqlparser-rs#1909 We now first try to use the respective function and then also consider columns. Fixes apache#14141.
Which issue does this PR close?
Fixes #14141.
Rationale for this change
When a reserved function like
useris called without parenthesis, it may as well be a column. This works in PostgreSQL for example:However sqlparser tries to detect these functions, see apache/datafusion-sqlparser-rs#1909
What changes are included in this PR?
We now first try to use the respective function and then also consider columns.
Are these changes tested?
More sqllogictests
Are there any user-facing changes?
More queries work as expected (IMHO).