Skip to content

Commit 5f9392a

Browse files
authored
SQL: Fix JdbcPreparedStatementIT.testDatetimeWithNanos (#107629) (#107686)
Fixes #105677
1 parent bc7468c commit 5f9392a

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
@@ -163,7 +163,7 @@ public void testDatetimeWithNanos() throws IOException, SQLException {
163163
versionSupportsDateNanos()
164164
);
165165

166-
long randomTimestampWitnNanos = randomTimeInNanos();
166+
long randomTimestampWitnNanos = randomTimestampWithNanos();
167167
int randomNanosOnly = extractNanosOnly(randomTimestampWitnNanos);
168168
setupIndexForDateTimeTestsWithNanos(randomTimestampWitnNanos);
169169

@@ -195,7 +195,7 @@ public void testDateTimeWithNanosAgainstDriverWithoutSupport() throws IOExceptio
195195
versionSupportsDateNanos()
196196
);
197197

198-
long randomTimestampWitnNanos = randomTimeInNanos();
198+
long randomTimestampWitnNanos = randomTimestampWithNanos();
199199
int randomNanosOnly = extractNanosOnly(randomTimestampWitnNanos);
200200
setupIndexForDateTimeTestsWithNanos(randomTimestampWitnNanos);
201201

@@ -218,6 +218,14 @@ public void testDateTimeWithNanosAgainstDriverWithoutSupport() throws IOExceptio
218218
}
219219
}
220220

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

0 commit comments

Comments
 (0)