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 @@ -205,10 +205,20 @@ private static Expression toTimestampLiteral(
Expression.TimeUnit.MICROSECONDS,
timeZone);
} else {
return Expression.literalTimestamp(
ts.getMillisecond() * 1_000_000 + ts.getNanoOfMillisecond(),
Expression.TimeUnit.NANOSECONDS,
timeZone);
// A TIMESTAMP value reaches year 9999, so nanoseconds since the epoch are not
// representable as an int64 outside roughly [1677-09-21, 2262-04-11]. A wrapped bound
// silently excludes matching rows, so refuse to push the literal down for the same
// reason as the grain checks above.
long nanos;
try {
nanos =
Math.addExact(
Math.multiplyExact(ts.getMillisecond(), 1_000_000L),
ts.getNanoOfMillisecond());
} catch (ArithmeticException e) {
return null;
}
return Expression.literalTimestamp(nanos, Expression.TimeUnit.NANOSECONDS, timeZone);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,27 @@ public void testTimestampMillisSubMillisecondLiteralNotPushed(
assertEquals(1_500L, rows.get(0).getTimestamp(0, 0).getMillisecond());
}

@Test
public void testTimestampNanosOverflowingLiteralNotPushed(@TempDir java.nio.file.Path tempDir)
throws Exception {
// epoch millis times 1_000_000 overflows int64 nanoseconds beyond 2262-04-11, and the
// wrapped bound landed before the epoch, so "< 9999-12-31" dropped the epoch row
RowType tsRowType = RowType.builder().field("f_ts", DataTypes.TIMESTAMP(9)).build();
PredicateBuilder tsBuilder = new PredicateBuilder(tsRowType);
List<Predicate> predicates =
Collections.singletonList(
tsBuilder.lessThan(0, Timestamp.fromEpochMillis(253402214400000L)));
assertNull(VortexPredicateConverter.toVortexExpression(predicates));
List<InternalRow> rows =
roundTrip(
tempDir,
tsRowType,
new GenericRow[] {GenericRow.of(Timestamp.fromEpochMillis(0L))},
predicates);
assertEquals(1, rows.size());
assertEquals(0L, rows.get(0).getTimestamp(0, 0).getMillisecond());
}

private List<InternalRow> roundTrip(
java.nio.file.Path tempDir,
RowType rowType,
Expand Down
Loading