Natural Join Column Qualification Conflict
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Describe the bug
Bug where NATURAL JOIN rejects source table column qualifiers in ORDER BY clause.
### To Reproduce
```
(base) ➜ ~ echo '"id","name","stuff"
1,"aaa",2
2,"bbb",1
3,"cc",1
4,"d",2' > test1.csv
(base) ➜ ~ datafusion-cli
DataFusion CLI v43.0.0
> CREATE EXTERNAL TABLE server
STORED AS CSV
LOCATION 'test1.csv';
0 row(s) fetched.
Elapsed 0.037 seconds.
> create table client(id int, name string, stuff int);
0 row(s) fetched.
Elapsed 0.007 seconds.
> select * from server;
+----+------+-------+
| id | name | stuff |
+----+------+-------+
| 1 | aaa | 2 |
| 2 | bbb | 1 |
| 3 | cc | 1 |
| 4 | d | 2 |
+----+------+-------+
4 row(s) fetched.
Elapsed 0.021 seconds.
> create table client(id int, name string, stuff int);
Execution error: Table 'client' already exists
> SELECT * FROM server NATURAL JOIN client AS client ORDER BY server.id;
Schema error: No field named server.id. Valid fields are client.id, client.name, client.stuff.
```
### Expected behavior
```
DataFusion CLI v41.0.0
> CREATE EXTERNAL TABLE server(id int, name string, stuff int)
STORED AS CSV
LOCATION 'test1.csv';
0 row(s) fetched.
Elapsed 0.005 seconds.
> create table client(id int, name string, stuff int);
0 row(s) fetched.
Elapsed 0.005 seconds.
> SELECT * FROM server NATURAL JOIN client AS client ORDER BY server.id;
+----+------+-------+
| id | name | stuff |
+----+------+-------+
+----+------+-------+
0 row(s) fetched.
Elapsed 0.020 seconds.
```
### Additional context
_No response_
Contributor guide
Research direction
Reproduce the NATURAL JOIN case in datafusion-cli, comparing ORDER BY server.id with the version shown for DataFusion v41.0.0. Trace the SQL query planning and name-resolution path for NATURAL JOIN and verify that server.id remains resolvable after the join while the expected query result is preserved.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100