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(mysql): TIMESTAMP -> CAST #2223

Merged
merged 3 commits into from
Sep 15, 2023
Merged

fix(mysql): TIMESTAMP -> CAST #2223

merged 3 commits into from
Sep 15, 2023

Conversation

barakalon
Copy link
Collaborator

cc @ginter

@@ -243,6 +243,10 @@ class Parser(parser.Parser):
format=exp.Literal.string("%B"),
),
"STR_TO_DATE": _str_to_date,
"TIMESTAMP": lambda args: exp.cast(
args[0],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

note: didn't use seq_get because it returns an optional type, and cast doesn't accept an optional

Copy link
Owner

Choose a reason for hiding this comment

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

you could avoid the cast then

exp.Cast(this=seq_get(), ...)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed it up a bit after reading mysql docs

Copy link
Owner

@tobymao tobymao left a comment

Choose a reason for hiding this comment

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

why is this needed?

@barakalon
Copy link
Collaborator Author

trying to transpile TIMESTAMP(x) to presto, which doesnt have such a function

@tobymao
Copy link
Owner

tobymao commented Sep 14, 2023

trying to transpile TIMESTAMP(x) to presto, which doesnt have such a function

wouldn't it make more sense to have presto generate the cast?

Copy link
Owner

@tobymao tobymao left a comment

Choose a reason for hiding this comment

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

let's do this on generation

@barakalon
Copy link
Collaborator Author

switched to generation. I'm a little scared because TIMESTAMP is also a type

@tobymao
Copy link
Owner

tobymao commented Sep 15, 2023

bigquery also has timestamp func

@barakalon
Copy link
Collaborator Author

Hm, yeah.
https://cloud.google.com/bigquery/docs/reference/standard-sql/timestamp_functions#timestamp

Seems like current implementation will still work, although we're overloading the expression arg for mysql and bigquery.

@tobymao tobymao merged commit 857e380 into main Sep 15, 2023
@tobymao tobymao deleted the barak/timestamp branch September 15, 2023 00:09
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.

2 participants