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 rounding in cast from TIME to TIMESTAMP #5742

Merged
merged 7 commits into from
Nov 2, 2020

Conversation

martint
Copy link
Member

@martint martint commented Oct 29, 2020

Fixes #5736

Relates to #5738

@findepi
Copy link
Member

findepi commented Oct 29, 2020

Fixes #5736, #5738

To fix #5738 we should apply checks to other types too:

  • length checks for char, varchar
  • space padding checks for char
  • ...

Copy link
Member

@findepi findepi left a comment

Choose a reason for hiding this comment

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

Couple comments, otherwise LGTM.

Per #5742 (comment), i think we should not close #5738 when merging this.

@@ -79,10 +79,6 @@ public static long round(long value, int magnitude)
*/
static long rescale(long value, int fromPrecision, int toPrecision)
{
if (value < 0) {
throw new IllegalArgumentException("value must be >= 0");
Copy link
Member

Choose a reason for hiding this comment

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

rescale method works great when the rounding is known to be not necessary.
For cases when rounding may be necessary, round, floorDiv seem to offer well defined semantics.

In this commit you're using the rounding-or-truncation of this method, but i'd change it to expect that value is pre-rounded. (actual check may be too expensive for runtime, idk).

This is more relevant when we allow negative numbers here.

Copy link
Member Author

Choose a reason for hiding this comment

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

rescale method works great when the rounding is known to be not necessary.

Correct, and that's the exact purpose of this method. The only reason we had this check is to protect against trying to rescale epoch values which can be negative. But it doesn't matter. I'll get rid of the call to rescale as you suggested above and revert this change.

This is to distinguish between the semantics of newInstance, which is not supposed to do
any conversions (rounding, etc), with the version that constructs a instance from an Instance
by applying any necessary rounding.
For negative numbers, it will produce a result different
from the original value, which is incorrect.
Previously, it was applying rounding rules, which ended up masking potential
problems in operations that are expected to do proper rounding.
They were in a separate class for when we had to parameterize the tests
for legacy vs new timestamp semantics. That's no longer necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Invalid result of TIME to TIMESTAMP cast for high precisions
2 participants