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

Wrap timestamp with "to_unixtime" when casting from timestamp to decimal #165

Merged
merged 2 commits into from
Oct 6, 2021

Conversation

jongn
Copy link
Contributor

@jongn jongn commented Oct 1, 2021

Hive allows casting TIMESTAMP type to DECIMAL type, which casts the timestamp into unix time with decimal type.

0: jdbc:hive2://localhost:10000> describe default.timestamp_test_base_2;
+-----------+------------+----------+
| col_name  | data_type  | comment  |
+-----------+------------+----------+
| t1        | timestamp  |          |
+-----------+------------+----------+
0: jdbc:hive2://localhost:10000> select cast(timestamp_test_base_2.t1 as decimal(10,0)) as d from default.timestamp_test_base_2;
+-------------+
|      d      |
+-------------+
| 1631137219  |
+-------------+

Trino/Presto does not allow for this kind of casting, and attempting the same query results in
Cannot cast timestamp to decimal(10,0)

So we propose mapping
CAST(timstamp_col AS DECIMAL(10,0))

To

CAST("to_unixtime"(timstamp_col) AS DECIMAL(10,0))

In order to achieve the same behavior.

Copy link
Collaborator

@ljfgem ljfgem left a comment

Choose a reason for hiding this comment

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

Thanks @jongn for the PR! Left some comments.

Copy link
Collaborator

@ljfgem ljfgem left a comment

Choose a reason for hiding this comment

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

LTGM, thanks @jongn
Integration test passed.

@ljfgem ljfgem merged commit e77c4e3 into linkedin:master Oct 6, 2021
@findepi
Copy link
Contributor

findepi commented Oct 6, 2021

heads up, @losipiuk found out that there is apparently some problem with this
trinodb/trino#9530 (comment)

@jongn
Copy link
Contributor Author

jongn commented Oct 8, 2021

Thx for the heads up @findepi !

I see that Jiefan has already sent pr to fix it: #169

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.

3 participants