-
Notifications
You must be signed in to change notification settings - Fork 1.5k
PARQUET-1388: Nanosecond precision time and timestamp - parquet-mr #519
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
Changes from 10 commits
c05bd86
fe47aad
e77f46f
8cbc47b
24728b1
badab75
8f41ef7
4f93e92
2681fcd
c00c98f
e66f220
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 |
|---|---|---|
|
|
@@ -23,10 +23,12 @@ | |
| import static java.util.concurrent.TimeUnit.MICROSECONDS; | ||
| import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
| import static java.util.concurrent.TimeUnit.MINUTES; | ||
| import static java.util.concurrent.TimeUnit.NANOSECONDS; | ||
| import static java.util.concurrent.TimeUnit.SECONDS; | ||
| import static org.apache.parquet.schema.PrimitiveStringifier.DATE_STRINGIFIER; | ||
| import static org.apache.parquet.schema.PrimitiveStringifier.DEFAULT_STRINGIFIER; | ||
| import static org.apache.parquet.schema.PrimitiveStringifier.INTERVAL_STRINGIFIER; | ||
| import static org.apache.parquet.schema.PrimitiveStringifier.TIME_NANOS_STRINGIFIER; | ||
| import static org.apache.parquet.schema.PrimitiveStringifier.TIME_STRINGIFIER; | ||
| import static org.apache.parquet.schema.PrimitiveStringifier.UNSIGNED_STRINGIFIER; | ||
| import static org.apache.parquet.schema.PrimitiveStringifier.UTF8_STRINGIFIER; | ||
|
|
@@ -200,6 +202,28 @@ public void testTimestampMicrosStringifier() { | |
| checkThrowingUnsupportedException(stringifier, Long.TYPE); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTimestampNanosStringifier() { | ||
| PrimitiveStringifier stringifier = PrimitiveStringifier.TIMESTAMP_NANOS_STRINGIFIER; | ||
|
|
||
| assertEquals("1970-01-01T00:00:00.000000000", stringifier.stringify(0l)); | ||
|
|
||
| Calendar cal = Calendar.getInstance(UTC); | ||
| cal.clear(); | ||
| cal.set(2053, Calendar.JULY, 10, 22, 13, 24); | ||
| cal.set(Calendar.MILLISECOND, 84); | ||
| long micros = cal.getTimeInMillis() * 1000_000 + 1900; | ||
|
Contributor
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. Please rename the variable to nanos and use 1_000_000 instead of 1000_000. |
||
| assertEquals("2053-07-10T22:13:24.084001900", stringifier.stringify(micros)); | ||
|
|
||
| cal.clear(); | ||
| cal.set(1848, Calendar.MARCH, 15, 9, 23, 59); | ||
| cal.set(Calendar.MILLISECOND, 765); | ||
| micros = cal.getTimeInMillis() * 1000_000 - 1; | ||
| assertEquals("1848-03-15T09:23:59.765000001", stringifier.stringify(micros)); | ||
|
Contributor
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. The timestamp from the calendar is 1848-03-15T09:23:59.765. You subtract 1 nanosec from it, so it should be 1 nanosec earlier than 1848-03-15T09:23:59.765, which is 1848-03-15T09:23:59.764999999 and not 1848-03-15T09:23:59.765000001. Why does this pass? |
||
|
|
||
| checkThrowingUnsupportedException(stringifier, Long.TYPE); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTimeStringifier() { | ||
| PrimitiveStringifier stringifier = TIME_STRINGIFIER; | ||
|
|
@@ -222,6 +246,20 @@ public void testTimeStringifier() { | |
| checkThrowingUnsupportedException(stringifier, Integer.TYPE, Long.TYPE); | ||
| } | ||
|
|
||
| @Test | ||
| public void testTimeNanoStringifier() { | ||
| PrimitiveStringifier stringifier = TIME_NANOS_STRINGIFIER; | ||
|
|
||
| assertEquals("00:00:00.000000000", stringifier.stringify(0l)); | ||
|
|
||
| assertEquals("12:34:56.789012987", stringifier.stringify(convert(NANOSECONDS, 12, 34, 56, 789012987))); | ||
| assertEquals("-12:34:56.000789012", stringifier.stringify(convert(NANOSECONDS, -12, -34, -56, -789012))); | ||
| assertEquals("12345:12:34.000056789", stringifier.stringify(convert(NANOSECONDS, 12345, 12, 34, 56789))); | ||
| assertEquals("-12345:12:34.000056789", stringifier.stringify(convert(NANOSECONDS, -12345, -12, -34, -56789))); | ||
|
|
||
| checkThrowingUnsupportedException(stringifier, Integer.TYPE, Long.TYPE); | ||
| } | ||
|
|
||
| private long convert(TimeUnit unit, long hours, long minutes, long seconds, long rest) { | ||
| return unit.convert(hours, HOURS) + unit.convert(minutes, MINUTES) + unit.convert(seconds, SECONDS) + rest; | ||
| } | ||
|
|
||
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: 1_000_000 (also a few lines below)