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 toMillis() should work for all presto timestamps #7506

Closed

Conversation

laithsakka
Copy link
Contributor

Summary:
Presto timestamps are in the range TimeStamp::minMillis() to TimeStamp::maxMillis().
moreover minMillis has a comment:

// The minimum Timestamp that toMillis() method will not overflow.
// Used to calculate the minimum value of the Presto timestamp.

Before this diff TimeStamp::minMillis().toMillis throws because the computation
overflows. However in that case we multiply negative number then add positive number
so the final result still fits in int64_t.
It is important the toMillis does not throw when it should not, since it is used in
functions like inPredicate() and other functions that do not expect it to throw
for some values. Throwing will show up as incorrect results compared to presto.
This diff fixes that .
I wonder if we shall throw a runtime error in toMillis() instead.

found while investigating #7161

Differential Revision: D51177715

Copy link

netlify bot commented Nov 9, 2023

Deploy Preview for meta-velox canceled.

Name Link
🔨 Latest commit 69fc2cb
🔍 Latest deploy log https://app.netlify.com/sites/meta-velox/deploys/654ea749881ad80008f20a2c

@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 Nov 9, 2023
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51177715

@laithsakka laithsakka changed the title Fix toMillis should not work for all presto timestamps Fix toMillis() should work for all presto timestamps Nov 9, 2023
laithsakka added a commit to laithsakka/velox that referenced this pull request Nov 9, 2023
…#7506)

Summary:

Presto timestamps are in the range TimeStamp::minMillis() to TimeStamp::maxMillis().
moreover minMillis has a comment:
```
// The minimum Timestamp that toMillis() method will not overflow.
// Used to calculate the minimum value of the Presto timestamp.
```
Before this diff  TimeStamp::minMillis().toMillis throws because the computation
overflows. However in that case we multiply negative number then add positive number
so the final result still fits in int64_t.
It is important the toMillis does not throw when it should not, since it is used in
functions like inPredicate() and other functions that do not expect it to throw
for some values. Throwing will show up as incorrect results compared to presto.
This diff fixes that .
I wonder if we shall throw a runtime error in toMillis() instead.

found while investigating facebookincubator#7161

Differential Revision: D51177715
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51177715

Copy link
Contributor

@kagamiori kagamiori left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for the fix!

(int64_t)(nanos_ / 1'000'000));
} catch (const std::exception& e) {
__int128_t result =
(__int128_t)seconds_ * 1'000 + (int64_t)(nanos_ / 1'000'000);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Use int128_t defined in Type.h.

laithsakka added a commit to laithsakka/velox that referenced this pull request Nov 10, 2023
…#7506)

Summary:

Presto timestamps are in the range TimeStamp::minMillis() to TimeStamp::maxMillis().
moreover minMillis has a comment:
```
// The minimum Timestamp that toMillis() method will not overflow.
// Used to calculate the minimum value of the Presto timestamp.
```
Before this diff  TimeStamp::minMillis().toMillis throws because the computation
overflows. However in that case we multiply negative number then add positive number
so the final result still fits in int64_t.
It is important the toMillis does not throw when it should not, since it is used in
functions like inPredicate() and other functions that do not expect it to throw
for some values. Throwing will show up as incorrect results compared to presto.
This diff fixes that .
I wonder if we shall throw a runtime error in toMillis() instead.

found while investigating facebookincubator#7161

Reviewed By: kagamiori

Differential Revision: D51177715
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51177715

…#7506)

Summary:

Presto timestamps are in the range TimeStamp::minMillis() to TimeStamp::maxMillis().
moreover minMillis has a comment:
```
// The minimum Timestamp that toMillis() method will not overflow.
// Used to calculate the minimum value of the Presto timestamp.
```
Before this diff  TimeStamp::minMillis().toMillis throws because the computation
overflows. However in that case we multiply negative number then add positive number
so the final result still fits in int64_t.
It is important the toMillis does not throw when it should not, since it is used in
functions like inPredicate() and other functions that do not expect it to throw
for some values. Throwing will show up as incorrect results compared to presto.
This diff fixes that .
I wonder if we shall throw a runtime error in toMillis() instead.

found while investigating facebookincubator#7161

Reviewed By: kagamiori

Differential Revision: D51177715
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D51177715

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 671e126.

Copy link

Conbench analyzed the 1 benchmark run on commit 671e1267.

There were no benchmark performance regressions. 🎉

The full Conbench report has more details.

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. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants