Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public static void serializeToIpc(VectorSchemaRoot vsr, OutputStream out) {

private static long nonCastedTimestampToEpoch(Timestamp timestamp, int precision) {
if (precision == 0) {
return timestamp.getMillisecond() / 1000;
return Math.floorDiv(timestamp.getMillisecond(), 1000L);
} else if (precision >= 1 && precision <= 3) {
return timestamp.getMillisecond();
} else if (precision >= 4 && precision <= 6) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ public void testWrite() {
}
}

@Test
public void testWritePreEpochSecondPrecisionTimestamp() {
RowType rowType =
RowType.of(DataTypes.TIMESTAMP(0), DataTypes.TIMESTAMP_WITH_LOCAL_TIME_ZONE(0));
try (ArrowFormatWriter writer = new ArrowFormatWriter(rowType, 16, true)) {
// 1969-12-31T23:59:59.500, i.e. 500 millis before the epoch
Timestamp preEpoch = Timestamp.fromEpochMillis(-500);
writer.write(GenericRow.of(preEpoch, preEpoch));
writer.flush();

VectorSchemaRoot vectorSchemaRoot = writer.getVectorSchemaRoot();
ArrowBatchReader arrowBatchReader = new ArrowBatchReader(rowType, true);
InternalRow row = arrowBatchReader.readBatch(vectorSchemaRoot).iterator().next();

// sub-second millis must be truncated towards negative infinity, not towards zero
assertThat(row.getTimestamp(0, 0).toString()).isEqualTo("1969-12-31T23:59:59");
assertThat(row.getTimestamp(1, 0).toString()).isEqualTo("1969-12-31T23:59:59");
}
}

@Test
public void testMissingMapColumnVectorizedRoundTrip() {
RowType inputRowType = RowType.builder().field("id", DataTypes.INT()).build();
Expand Down
Loading