Support columns having the same alias
- Dominant language
- Rust
- Stars
- 9.3k
- Forks
- 2.4k
- Avg merge
- 3d 7h
- Merged PRs (30d)
- 344
Description
### Describe the bug
When we give the same aliases for multiple columns (`SELECT ts as c1, inc_col as c1 FROM annotated_data_infinite`), builder gives such an error:
`Plan("Projections require unique expression names but the expression \"annotated_data_infinite.ts AS c1\" at position 0 and \"annotated_data_infinite.inc_col AS c1\" at position 1 have the same name. Consider aliasing (\"AS\") one of them.")`
### To Reproduce
```
ctx.sql(
"CREATE EXTERNAL TABLE annotated_data_infinite (
ts INTEGER,
inc_col INTEGER,
desc_col INTEGER,
)
STORED AS CSV
WITH HEADER ROW
WITH ORDER (ts ASC)
LOCATION '/Users/berkaysahin/Desktop/arrow-datafusion/datafusion/core/tests/data/window_1.csv'",
)
.await?;
let sql = "SELECT ts as c1, inc_col as c1 FROM annotated_data_infinite";
let dataframe = ctx.sql(sql).await.expect(&msg);
```
### Expected behavior
Postgre can handle it and gives result with two columns having the same name. I don't know this is an intentional behaviour in Datafusion or a bug, but I would like to open an issue.
### Additional context
_No response_
Contributor guide
Research direction
Start with the SQL reproduction in the issue: SELECT ts as c1, inc_col as c1 FROM annotated_data_infinite, and trace the planner path that reports duplicate projection names. Compare the resulting behavior with the stated PostgreSQL expectation; done means the query's two same-named output columns are handled consistently and the relevant behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust, sql
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100