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

Add from_unixtime_nanos operation #5046

Merged
merged 1 commit into from Oct 6, 2020

Conversation

alec-heif
Copy link
Contributor

@alec-heif alec-heif commented Sep 1, 2020

This addresses the nanos use case of #5046 and also adds support for converting nanos that don't fit in a BIGINT.

Related to #5038

@cla-bot
Copy link

cla-bot bot commented Sep 1, 2020

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please submit the signed CLA to cla@prestosql.io. For more information, see https://github.com/prestosql/cla.

@alec-heif
Copy link
Contributor Author

I signed + emailed the CLA yesterday but I guess it hasn't been processed yet

@martint
Copy link
Member

martint commented Sep 1, 2020

@cla-bot check

@cla-bot cla-bot bot added the cla-signed label Sep 1, 2020
@cla-bot
Copy link

cla-bot bot commented Sep 1, 2020

The cla-bot has been summoned, and re-checked this pull request!

@alec-heif alec-heif changed the title Implement from_unixtime_nanos Add from_unixtime_nanos operation Sep 3, 2020
@alec-heif alec-heif marked this pull request as ready for review September 3, 2020 23:00
@mosabua mosabua added the needs-docs This pull request requires changes to the documentation label Sep 10, 2020
Copy link
Member

@losipiuk losipiuk left a comment

Choose a reason for hiding this comment

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

Thanks!
Would you be fine also adding documentation to datetime.rst?

Also please update PR message to reference #5038

Comment on lines 153 to 154
long epochSeconds = unixTimeNanos / Timestamps.NANOSECONDS_PER_SECOND;
long nanosOfSecond = unixTimeNanos % Timestamps.NANOSECONDS_PER_SECOND;
Copy link
Member

Choose a reason for hiding this comment

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

This needs to use floorDiv and floorMod to produce correct results when the input is negative. In particular, nanosOfSecond should never be negative

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah interesting, do we need to consider negative unix timestamps as valid? I would prefer to throw when they are encountered.

Copy link
Member

Choose a reason for hiding this comment

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

I don't see why not.

From wikipedia (https://en.wikipedia.org/wiki/Unix_time)

The Unix time number is zero at the Unix epoch, and increases by exactly 86400 per day since the epoch. Thus 2004-09-16T00:00:00Z, 12677 days after the epoch, is represented by the Unix time number 12677 × 86400 = 1095292800. This can be extended backwards from the epoch too, using negative numbers;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 ok will do

Copy link
Member

@martint martint left a comment

Choose a reason for hiding this comment

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

Looks good. Can you rebase and squash the commits before I merge it?

@alec-heif alec-heif force-pushed the alec-heif/from_unixtime_nanos branch from 4ccf90d to 7e0ff8d Compare October 1, 2020 22:38
@alec-heif
Copy link
Contributor Author

Looks good. Can you rebase and squash the commits before I merge it?

Thanks @martint , should be good to go now!

@alec-heif alec-heif force-pushed the alec-heif/from_unixtime_nanos branch from 7e0ff8d to c5c6b7d Compare October 1, 2020 22:41
@martint martint merged commit b14fc99 into trinodb:master Oct 6, 2020
@martint martint mentioned this pull request Oct 6, 2020
10 tasks
@martint martint added this to the 344 milestone Oct 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla-signed needs-docs This pull request requires changes to the documentation
Development

Successfully merging this pull request may close these issues.

None yet

4 participants