Skip to content

Commit

Permalink
SQL: Fix JdbcPreparedStatementIT.testDatetimeWithNanos (#107629)
Browse files Browse the repository at this point in the history
Fixes #105677
  • Loading branch information
bpintea authored Apr 22, 2024
1 parent a67613e commit f77f982
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public void testDatetimeWithNanos() throws IOException, SQLException {
versionSupportsDateNanos()
);

long randomTimestampWitnNanos = randomTimeInNanos();
long randomTimestampWitnNanos = randomTimestampWithNanos();
int randomNanosOnly = extractNanosOnly(randomTimestampWitnNanos);
setupIndexForDateTimeTestsWithNanos(randomTimestampWitnNanos);

Expand Down Expand Up @@ -195,7 +195,7 @@ public void testDateTimeWithNanosAgainstDriverWithoutSupport() throws IOExceptio
versionSupportsDateNanos()
);

long randomTimestampWitnNanos = randomTimeInNanos();
long randomTimestampWitnNanos = randomTimestampWithNanos();
int randomNanosOnly = extractNanosOnly(randomTimestampWitnNanos);
setupIndexForDateTimeTestsWithNanos(randomTimestampWitnNanos);

Expand All @@ -218,6 +218,14 @@ public void testDateTimeWithNanosAgainstDriverWithoutSupport() throws IOExceptio
}
}

private static long randomTimestampWithNanos() {
long randomTimestampWithNanos = randomTimeInNanos();
// Indexing will jiggle the value by adding -1, 0, 1. The query will truncate it from ns to ms and expect no match. If the
// jiggled value will round to no sub-ms fraction, the query will match. So ensure that won't happen.
randomTimestampWithNanos += (randomTimestampWithNanos % 1_000_000 < 10) ? 10 : 0;
return randomTimestampWithNanos;
}

public void testDate() throws IOException, SQLException {
long randomMillis = randomLongBetween(1, DateUtils.MAX_MILLIS_BEFORE_9999);
setupIndexForDateTimeTests(randomMillis);
Expand Down

0 comments on commit f77f982

Please sign in to comment.