Skip to content

Conversation

@crepererum
Copy link
Contributor

Which issue does this PR close?

Fixes #14141.

Rationale for this change

When a reserved function like user is called without parenthesis, it may as well be a column. This works in PostgreSQL for example:

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

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).

@github-actions github-actions bot added sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Jul 3, 2025
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.
@crepererum crepererum force-pushed the crepererum/issue14141 branch from 7adc63a to 95805f0 Compare July 3, 2025 10:19
@crepererum crepererum marked this pull request as ready for review July 3, 2025 12:05
Copy link
Contributor

@alamb alamb left a 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,
Copy link
Contributor

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:

Suggested change
function_without_paranthesis: bool,
function_without_parenthesis: bool,

Copy link
Member

@jonahgao jonahgao left a 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!

@alamb
Copy link
Contributor

alamb commented Jul 8, 2025

Thank you for the review @jonahgao ❤️

@alamb alamb merged commit 2884612 into apache:main Jul 8, 2025
27 checks passed
epsio-kogro pushed a commit to Epsio-Labs/arrow-datafusion that referenced this pull request Jul 13, 2025
…#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.
epsio-kogro pushed a commit to Epsio-Labs/arrow-datafusion that referenced this pull request Jul 13, 2025
…#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.
epsio-kogro pushed a commit to Epsio-Labs/arrow-datafusion that referenced this pull request Jul 13, 2025
…#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.
epsio-kogro pushed a commit to Epsio-Labs/arrow-datafusion that referenced this pull request Jul 16, 2025
…#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.
ThinkRedstone pushed a commit to Epsio-Labs/arrow-datafusion that referenced this pull request Sep 29, 2025
…#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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error when use user field in where clause

3 participants