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

bug - switching between 0 and 1 based indexes #68

Closed
staubda opened this issue Feb 2, 2022 · 1 comment · Fixed by #71
Closed

bug - switching between 0 and 1 based indexes #68

staubda opened this issue Feb 2, 2022 · 1 comment · Fixed by #71

Comments

@staubda
Copy link

staubda commented Feb 2, 2022

Hive uses 0-based indexing, while Presto uses 1-based indexing, however in the following example sqlglot doesn't properly translate between the two:

print(sqlglot.transpile("""
SELECT
    SPLIT(str_col_with_space, ' ')[0]
FROM
    my_db.my_table
""", read='hive', write='presto', pretty=True)[0])

returns the query unchanged, but it should be

SELECT
    SPLIT(str_col_with_space, ' ')[1]
FROM
    my_db.my_table

and conversely

print(sqlglot.transpile("""
SELECT
    SPLIT(str_col_with_space, ' ')[1]
FROM
    my_db.my_table
""", read='presto', write='hive', pretty=True)[0])

returns the query unchanged, but it should be

SELECT
    SPLIT(str_col_with_space, ' ')[0]
FROM
    my_db.my_table

This is particularly dangerous when going from presto --> hive, as the wrongly translated code will always still be syntactically correct.

@staubda
Copy link
Author

staubda commented Feb 2, 2022

this is using version 1.22.0

tobymao added a commit that referenced this issue Feb 7, 2022
fixes #68
triggers warnings because it may not be correct for certain cases like
maps with integer indicies
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

Successfully merging a pull request may close this issue.

1 participant