Skip to content

Commit 99a68a8

Browse files
authored
SQL: Fix JdbcPreparedStatementIT.testDatetimeWithNanos (#107629) (#107687)
Fixes #105677
1 parent 9b58752 commit 99a68a8

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

x-pack/plugin/sql/qa/jdbc/src/main/java/org/elasticsearch/xpack/sql/qa/jdbc/PreparedStatementTestCase.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public void testDatetimeWithNanos() throws IOException, SQLException {
160160
versionSupportsDateNanos()
161161
);
162162

163-
long randomTimestampWitnNanos = randomTimeInNanos();
163+
long randomTimestampWitnNanos = randomTimestampWithNanos();
164164
int randomNanosOnly = extractNanosOnly(randomTimestampWitnNanos);
165165
setupIndexForDateTimeTestsWithNanos(randomTimestampWitnNanos);
166166

@@ -192,7 +192,7 @@ public void testDateTimeWithNanosAgainstDriverWithoutSupport() throws IOExceptio
192192
versionSupportsDateNanos()
193193
);
194194

195-
long randomTimestampWitnNanos = randomTimeInNanos();
195+
long randomTimestampWitnNanos = randomTimestampWithNanos();
196196
int randomNanosOnly = extractNanosOnly(randomTimestampWitnNanos);
197197
setupIndexForDateTimeTestsWithNanos(randomTimestampWitnNanos);
198198

@@ -215,6 +215,14 @@ public void testDateTimeWithNanosAgainstDriverWithoutSupport() throws IOExceptio
215215
}
216216
}
217217

218+
private static long randomTimestampWithNanos() {
219+
long randomTimestampWithNanos = randomTimeInNanos();
220+
// 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
221+
// jiggled value will round to no sub-ms fraction, the query will match. So ensure that won't happen.
222+
randomTimestampWithNanos += (randomTimestampWithNanos % 1_000_000 < 10) ? 10 : 0;
223+
return randomTimestampWithNanos;
224+
}
225+
218226
public void testDate() throws IOException, SQLException {
219227
long randomMillis = randomLongBetween(1, DateUtils.MAX_MILLIS_BEFORE_9999);
220228
setupIndexForDateTimeTests(randomMillis);

0 commit comments

Comments
 (0)