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

[Datafusion] Datafusion queries involving a column name that begins with a number produces unexpected results #108

Closed
alamb opened this issue Apr 26, 2021 · 3 comments
Labels
datafusion Changes in the datafusion crate

Comments

@alamb
Copy link
Contributor

alamb commented Apr 26, 2021

Note: migrated from original JIRA: https://issues.apache.org/jira/browse/ARROW-10329

This bug can be worked around by wrapping column names in quotes.

Example:

{{let query = "SELECT 16_20mph, 21_25mph FROM foo;"}}

{{let logical_plan = ctx.create_logical_plan(query)?;}}

{{logical_plan.schema().fields() now has fields: [_20mph, _25mph]}}

The resulting table produced by this query looks like:
||{{_20mph}}||{{_25mph}}||
|16|21|
|16|21|

Every row is identical, where the column value is equal to the initial number that appears in the column name.

@alamb alamb added the datafusion Changes in the datafusion crate label Apr 26, 2021
@alamb
Copy link
Contributor Author

alamb commented Apr 26, 2021

Comment from Ben Sully(sd2k) @ 2020-11-08T11:46:18.008+0000:

This behaviour seems consistent with Postgres at least:


{{❯ psql}}
{{psql (12.4)}}
{{Type "help" for help.}}

{{ben=# create table foo ("16_20mph" integer, "21_25mph" integer);}}
{{CREATE TABLE}}
{{ben=# insert into foo values (1, 2), (3, 4);}}
{{INSERT 0 2}}
{{ben=# SELECT 16_20mph, 21_25mph FROM foo;}}
{{ _20mph | _25mph }}
{{--------+--------}}
{{ 16 | 21}}
{{ 16 | 21}}
{{(2 rows)}}

{{ben=# SELECT "16_20mph", "21_25mph" FROM foo;}}
{{ 16_20mph | 21_25mph }}
{{----------+----------}}
{{ 1 | 2}}
{{ 3 | 4}}
{{(2 rows)}}

@Jefffrey
Copy link
Contributor

Jefffrey commented Jan 7, 2023

I believe this can be closed as its expected behaviour stemming from sqlparser, recent relevant discussion: apache/datafusion-sqlparser-rs#768 (comment)

@alamb
Copy link
Contributor Author

alamb commented Jan 8, 2023

I agree -- thanks @Jefffrey -- I agree this is "expected behavior" in the sense that it is what postgres does even though it is not very obvious

@alamb alamb closed this as completed Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
datafusion Changes in the datafusion crate
Projects
None yet
Development

No branches or pull requests

2 participants