-
Notifications
You must be signed in to change notification settings - Fork 57
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
SNOW-1032874: Fix an Overflow Issue for Integer-store Timestamp #673
Conversation
long val = Long.parseLong(input); | ||
|
||
if (val > -SECONDS_LIMIT_FOR_EPOCH && val < SECONDS_LIMIT_FOR_EPOCH) { | ||
epochNanos = BigInteger.valueOf(val).multiply(BigInteger.valueOf(Power10.intTable[9])); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit, use Power10.sb16Table[9]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
Assert.assertEquals(123000000, wrapper.getFraction()); | ||
Assert.assertEquals(new BigInteger("1609462800123000000"), wrapper.toBinary(false)); | ||
|
||
// Test integer-stored time and scale guessing | ||
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we also need integration test coverage, which would test JDBC compatibility. We have a bunch of IT tests for scale guessing in DateTimeIT.java, just not for these edge cases. Could you add tests along the lines of these?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added
…-ingest-java into tzhang-si-overflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm! thank you
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Will merge this one first, we might need to update the logic again once we hear back from SQL folks about the behavior for negative timestamps. |
According to https://docs.snowflake.com/en/sql-reference/functions/to_timestamp#usage-notes:
Due to the multiplication logic in the code, we run into an overflow issue when the input is bigger than a certain value (for example: 31535999999999) and it causes silent corrupted values in the table, this change updates the code to use BigInteger instead of long to resolve the overflow issue.