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

Feat(presto): transpile 'epoch' to '1970-01-01 00:00:00' in time-like casts #1726

Merged
merged 1 commit into from
Jun 6, 2023

Conversation

georgesittas
Copy link
Collaborator

@georgesittas georgesittas commented Jun 6, 2023

Fixes #1725

Haven't investigated much, so I'm not sure if this transformation is 100% correct; for the example in #1725 it works fine.

However, one difference is that Spark produces the following when casting 'epoch' to a timezone:

spark-sql (default)> select cast('epoch' as timestamp);
1970-01-01 02:00:00

Whereas this transformation yields the following when transpiling the above from Spark to Trino:

trino> SELECT TRY_CAST('1970-01-01 00:00:00' AS TIMESTAMP);
          _col0          
-------------------------
 1970-01-01 00:00:00.000 
(1 row)

Not sure why it produces 02:00:00 in the former case.. Maybe it's interpreting the 'epoch' using a different timezone?

if (
isinstance(expression, (exp.Cast, exp.TryCast))
and expression.name.lower() == "epoch"
and expression.to.this in exp.DataType.TEMPORAL_TYPES
Copy link
Collaborator Author

@georgesittas georgesittas Jun 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the TEMPORAL_TYPES check to ensure correctness in the general case, although maybe we can get rid of it? Not sure what else one would want to cast 'epoch' into.

@tobymao tobymao merged commit dd29f3f into main Jun 6, 2023
@tobymao tobymao deleted the jo/presto_cast_epoch branch June 6, 2023 16:19
adrianisk pushed a commit to adrianisk/sqlglot that referenced this pull request 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

Successfully merging this pull request may close these issues.

cannot correctly convert syntax "timestamp 'epoch'" from redshift to presto/trino
2 participants