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 timestamp and timezone management documentation #10036

Closed

Conversation

pedroerp
Copy link
Contributor

@pedroerp pedroerp commented Jun 4, 2024

Adding a new documentation page to describe details of management of timestamps, timezone and conversions in Velox.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 4, 2024
@pedroerp pedroerp requested a review from mbasmanova June 4, 2024 04:38
Copy link

netlify bot commented Jun 4, 2024

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 96daf21
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/66627c7c80d08a0008ad4209

@pedroerp pedroerp requested review from zacw7 and svm1 June 4, 2024 04:39
@pedroerp
Copy link
Contributor Author

pedroerp commented Jun 4, 2024

Cc: @PHILO-HE

@facebook-github-bot
Copy link
Contributor

@pedroerp has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Copy link
Contributor

@mbasmanova mbasmanova left a comment

Choose a reason for hiding this comment

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

Thank you for putting this together. Super useful. Some nits.

reading of a wall clock and a calendar, e.g, ``2024-04-09 18:25:00``. Note that
a TIMESTAMP does not represent an absolute point in time, as the exact same
wall clock time may be read in different instants in time depending on where
one is situated on earth. For example, ``2024-04-09 18:25:00`` in California
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: wondering if earth should be Earth

a TIMESTAMP does not represent an absolute point in time, as the exact same
wall clock time may be read in different instants in time depending on where
one is situated on earth. For example, ``2024-04-09 18:25:00`` in California
and in China were perceived at different absolute points in time, about 15h
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: 15h -> 15 hours

* While “seconds” can be negative to represent time before ``1970-01-01
00:00:00``, “nanoseconds” are always positive.

* Engines like Presto and Spark only support milliseconds precision, so
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe Spark supports at least microseconds precision.

00:00:00``, “nanoseconds” are always positive.

* Engines like Presto and Spark only support milliseconds precision, so
naturally “nanoseconds” are zeroed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nanoseconds are used even with millisecond precision.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rephrased it

TimestampWithTimezones are serialized, for example.

**TimestampWithTimezone:** To represent an absolute point in time, Velox provides
the `TimestampWithTimezone class <https://github.com/facebookincubator/velox/blob/main/velox/functions/prestosql/types/TimestampWithTimeZoneType.h>`_.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think there is a TimestampWithTimezone class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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


**TimestampWithTimezone:** To represent an absolute point in time, Velox provides
the `TimestampWithTimezone class <https://github.com/facebookincubator/velox/blob/main/velox/functions/prestosql/types/TimestampWithTimeZoneType.h>`_.
This class implements the TIMESTAMP WITH TIMEZONE sql semantic discussed above,
Copy link
Contributor

Choose a reason for hiding this comment

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

sql -> SQL

**TimestampWithTimezone:** To represent an absolute point in time, Velox provides
the `TimestampWithTimezone class <https://github.com/facebookincubator/velox/blob/main/velox/functions/prestosql/types/TimestampWithTimeZoneType.h>`_.
This class implements the TIMESTAMP WITH TIMEZONE sql semantic discussed above,
and was based on Presto’s implementation - therefore only supporting
Copy link
Contributor

Choose a reason for hiding this comment

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

was based -> is based

millisecond-precision.

TimestampWithTimezone physically packs two integers in a single 64 word, using
12 bits for timezone ID, and 52 for a millisecond-precision timestamp.
Copy link
Contributor

Choose a reason for hiding this comment

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

52 -> 52 bits


.. code-block:: bash

$ rpm -qa | grep tzdata
Copy link
Contributor

Choose a reason for hiding this comment

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

I tried this command on my Mac, but it didn't print anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is for linux; added to the text to clarify

Copy link
Contributor

@zacw7 zacw7 left a comment

Choose a reason for hiding this comment

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

Thanks for composing this doc. This is super helpful!


To represent absolute points in time, SQL defines a TIMESTAMP WITH TIMEZONE
type, which conceptually represents a pair of a wall time and calendar read
(say, ``2024-04-09 18:25:00``), and a timezone (``PST``, or
Copy link
Contributor

Choose a reason for hiding this comment

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

April should be in PDT instead of PST at America/Los_Angeles. Or we can just put PT here.


.. code-block:: sql

presto:de> select typeof(TIMESTAMP '1970-01-01 00:00:00');
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's omit the presto:de part? Should we keep the format of the examples consistent as https://facebookincubator.github.io/velox/functions/presto/conversion.html#cast-to-timestamp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice! That's better

Adding a new documentation page to describe details of management of
timestamp, timezone and conversions in Velox.
@facebook-github-bot
Copy link
Contributor

@pedroerp has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@pedroerp merged this pull request in d670da3.

Copy link

Conbench analyzed the 1 benchmark run on commit d670da38.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

Joe-Abraham pushed a commit to Joe-Abraham/velox that referenced this pull request Jun 7, 2024
…r#10036)

Summary:
Adding a new documentation page to describe details of management of timestamps, timezone and conversions in Velox.

Pull Request resolved: facebookincubator#10036

Reviewed By: mbasmanova, zacw7

Differential Revision: D58172617

Pulled By: pedroerp

fbshipit-source-id: a8fc2e5a78bd65bf587b65e3296ef3c27f23da28
Joe-Abraham pushed a commit to Joe-Abraham/velox that referenced this pull request Jun 7, 2024
…r#10036)

Summary:
Adding a new documentation page to describe details of management of timestamps, timezone and conversions in Velox.

Pull Request resolved: facebookincubator#10036

Reviewed By: mbasmanova, zacw7

Differential Revision: D58172617

Pulled By: pedroerp

fbshipit-source-id: a8fc2e5a78bd65bf587b65e3296ef3c27f23da28
deepashreeraghu pushed a commit to deepashreeraghu/velox that referenced this pull request Jun 13, 2024
…r#10036)

Summary:
Adding a new documentation page to describe details of management of timestamps, timezone and conversions in Velox.

Pull Request resolved: facebookincubator#10036

Reviewed By: mbasmanova, zacw7

Differential Revision: D58172617

Pulled By: pedroerp

fbshipit-source-id: a8fc2e5a78bd65bf587b65e3296ef3c27f23da28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants