-
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
Changes from 3 commits
a31a4b6
a5bce3d
e365bb6
27ce579
aecd879
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
import java.math.BigDecimal; | ||
import java.math.BigInteger; | ||
import java.nio.charset.StandardCharsets; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.time.Instant; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
|
@@ -251,20 +253,47 @@ public void testValidateAndParseTime() { | |
} | ||
|
||
@Test | ||
public void testValidateAndParseTimestamp() { | ||
public void testValidateAndParseTimestamp() throws ParseException { | ||
TimestampWrapper wrapper = | ||
DataValidationUtil.validateAndParseTimestamp( | ||
"COL", "2021-01-01T01:00:00.123+01:00", 4, UTC, false, 0); | ||
assertEquals(1609459200, wrapper.getEpoch()); | ||
assertEquals(1609459200, wrapper.getEpochSecond()); | ||
assertEquals(123000000, wrapper.getFraction()); | ||
assertEquals(3600, wrapper.getTimezoneOffsetSeconds()); | ||
assertEquals(1500, wrapper.getTimeZoneIndex()); | ||
|
||
wrapper = validateAndParseTimestamp("COL", " 2021-01-01T01:00:00.123 \t\n", 9, UTC, true, 0); | ||
Assert.assertEquals(1609462800, wrapper.getEpoch()); | ||
Assert.assertEquals(1609462800, wrapper.getEpochSecond()); | ||
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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
assertEquals( | ||
BigInteger.valueOf(df.parse("1971-01-01 00:00:00.001").getTime()) | ||
.multiply(BigInteger.valueOf(1000000)), | ||
validateAndParseTimestamp("COL", "31536000001", 9, UTC, true, 0).toBinary(false)); | ||
|
||
assertEquals( | ||
BigInteger.valueOf(df.parse("2969-05-02 23:59:59.999").getTime()) | ||
.multiply(BigInteger.valueOf(1000000)), | ||
validateAndParseTimestamp("COL", "31535999999999", 9, UTC, true, 0).toBinary(false)); | ||
|
||
assertEquals( | ||
BigInteger.valueOf(df.parse("1971-01-01 00:00:00.000").getTime()) | ||
.multiply(BigInteger.valueOf(1000000)), | ||
validateAndParseTimestamp("COL", "31536000000000", 9, UTC, true, 0).toBinary(false)); | ||
|
||
assertEquals( | ||
BigInteger.valueOf(df.parse("2969-05-02 23:59:59.999").getTime()) | ||
.multiply(BigInteger.valueOf(1000000)), | ||
validateAndParseTimestamp("COL", "31535999999999", 9, UTC, true, 0).toBinary(false)); | ||
|
||
assertEquals( | ||
BigInteger.valueOf(df.parse("1971-01-01 00:00:00.000").getTime()) | ||
.multiply(BigInteger.valueOf(1000000)), | ||
validateAndParseTimestamp("COL", "31536000000000000", 9, UTC, true, 0).toBinary(false)); | ||
|
||
// Time input is not supported | ||
expectError( | ||
ErrorCode.INVALID_VALUE_ROW, | ||
|
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