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

cast expression may cause duplicate column name error #5174

Closed
gaoxinge opened this issue Feb 4, 2023 · 4 comments
Closed

cast expression may cause duplicate column name error #5174

gaoxinge opened this issue Feb 4, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@gaoxinge
Copy link
Contributor

gaoxinge commented Feb 4, 2023

Is your feature request related to a problem or challenge? Please describe what you are trying to do.

This problem origin from dask-contrib/dask-sql#948, which can be minimally reproduced by

SELECT 10, cast(10 as tinyint)

The sql above will cause the duplicate column name error. And this is because

  • cast use the expr as column name

https://github.com/apache/arrow-datafusion/blob/224c682101949da57aebc36e92e5a881ef3040d4/datafusion/expr/src/expr.rs#L1203-L1210

  • same column name is not valid

https://github.com/apache/arrow-datafusion/blob/224c682101949da57aebc36e92e5a881ef3040d4/datafusion/expr/src/logical_plan/builder.rs#L925-L948

Describe the solution you'd like

There are two soluntions here:

  1. rename the column name of cast expression

For example, mysql use the whole cast expression as column name, like CAST(Int64(10) AS Int8) instead of Int64(10). In this way, the column name of cast expression will be more precise, and also this can bypass the duplicate column name error.

  1. remove the unique column name validation

In mysql and sql server, query support same column name. So I think we can remove the unique column name validation to make same column name coexist.

@gaoxinge gaoxinge added the enhancement New feature or request label Feb 4, 2023
@alamb
Copy link
Contributor

alamb commented Feb 4, 2023

I think @andygrove and @xudong963 may have had thoughts on this topic previously

@alamb
Copy link
Contributor

alamb commented Feb 4, 2023

Also, possibly related -- #4723 from @comphead

@comphead
Copy link
Contributor

comphead commented Feb 4, 2023

Thanks @gaoxinge for reporting this, I'm planning to start work on this as @andygrove agreed here #3990 (comment)

@gaoxinge
Copy link
Contributor Author

gaoxinge commented Feb 6, 2023

@alamb @comphead Thx for reply, and I see the progress and direction of this issue.

@gaoxinge gaoxinge closed this as completed Feb 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants