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

Fix!: StrToUnix Hive parsing, Presto generation fixes #3225

Merged
merged 1 commit into from Mar 26, 2024

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented Mar 26, 2024

Fixes #3221

There were a couple of issues here. The first one is:

>>> import sqlglot
>>> sqlglot.transpile("unix_timestamp()", "hive", "presto")
["TO_UNIXTIME(DATE_PARSE('%Y-%m-%d %T'))"]

This DATE_PARSE call is invalid in Presto / Trino - we need an argument to parse.

The second one was a bit more nuanced and I don't really like my current solution, but didn't see another way out during my investigation. Basically, DATE_PARSE doesn't handle time zone information, and so the following breaks in Presto:

-- "2024-03-26 13:52:38.634 UTC" is malformed at ".634 UTC"
select date_parse(cast(current_timestamp as varchar), '%Y-%m-%d %T');

The workaround I implemented it basically to try calling both DATE_PARSE and PARSE_DATETIME, because if the former fails due to encountering a time zone, the latter will parse it just fine. There was a refactor to allow format_time to use different time format bindings, since PARSE_DATETIME supports different date/time formats.

References:

@georgesittas georgesittas merged commit 0919be5 into main Mar 26, 2024
5 checks passed
@georgesittas georgesittas deleted the jo/unix_presto_fixes branch March 26, 2024 22:58
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 this pull request may close these issues.

unix_timestamp() is Error
2 participants