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

SparkSQL: TABLESAMPLE with aliased database.table_name fails #1629

Closed
CDonnerer opened this issue May 15, 2023 · 2 comments
Closed

SparkSQL: TABLESAMPLE with aliased database.table_name fails #1629

CDonnerer opened this issue May 15, 2023 · 2 comments
Assignees

Comments

@CDonnerer
Copy link

Fully reproducible code snippet

1/ using transpile:

import sqlglot

query = "SELECT * FROM my_database.my_table TABLESAMPLE (1 PERCENT) foo"
sqlglot.transpile(query, read="spark")
SELECT * FROM my_table TABLESAMPLE (1 PERCENT) AS foo

here my_database is missing, expected:

SELECT * FROM my_database.my_table TABLESAMPLE (1 PERCENT) AS foo

2/ using parse_one:

import sqlglot

query = "SELECT * FROM my_database.my_table TABLESAMPLE (1 PERCENT) foo"
sqlglot.parse_one(query, read="spark")
SELECT * FROM my_database.my_table AS foo TABLESAMPLE (1 PERCENT)

here the alias is misplaced, expected:

SELECT * FROM my_database.my_table TABLESAMPLE (1 PERCENT) AS foo

Official Documentation

https://spark.apache.org/docs/latest/sql-ref-syntax-qry-select-sampling.html

See also here for example snippets https://github.com/sqlfluff/sqlfluff/blob/main/test/fixtures/dialects/hive/select_sampling_table.sql

@tobymao tobymao self-assigned this May 15, 2023
@tobymao
Copy link
Owner

tobymao commented May 15, 2023

in the second case, this is expected because you didn't specify an output dialect, try it with sql(dialect="spark")

@CDonnerer
Copy link
Author

Awesome, thanks a lot for the super quick fix!

adrianisk pushed a commit to adrianisk/sqlglot that referenced this issue Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants