Skip to content

Commit d0fb8dc

Browse files
committed
Change the milliseconds precision to 3 digits for intervals. (elastic#38297)
(cherry picked from commit cea81b1)
1 parent c5bccb1 commit d0fb8dc

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/literal/Intervals.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public static TemporalAmount negate(TemporalAmount interval) {
332332
int MAX_HOUR = 23;
333333
int MAX_MINUTE = 59;
334334
int MAX_SECOND = 59;
335-
int MAX_MILLI = 999999999;
335+
int MAX_MILLI = 999;
336336

337337
char DOT = '.';
338338
char SPACE = ' ';

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/expression/literal/IntervalsTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public void testMinuteInterval() throws Exception {
8383

8484
public void testSecondInterval() throws Exception {
8585
int randomSeconds = randomNonNegativeInt();
86-
int randomMillis = randomBoolean() ? (randomBoolean() ? 0 : 999999999) : randomInt(999999999);
86+
int randomMillis = randomBoolean() ? (randomBoolean() ? 0 : 999) : randomInt(999);
8787
String value = format(Locale.ROOT, "%s%d.%d", sign, randomSeconds, randomMillis);
8888
TemporalAmount amount = parseInterval(EMPTY, value, INTERVAL_SECOND);
8989
assertEquals(maybeNegate(sign, Duration.ofSeconds(randomSeconds).plusMillis(randomMillis)), amount);
@@ -128,7 +128,7 @@ public void testDayToSecond() throws Exception {
128128
int randomSecond = randomInt(59);
129129

130130
boolean withMillis = randomBoolean();
131-
int randomMilli = withMillis ? randomInt(999999999) : 0;
131+
int randomMilli = withMillis ? randomInt(999) : 0;
132132
String millisString = withMillis ? "." + randomMilli : "";
133133

134134
String value = format(Locale.ROOT, "%s%d %d:%d:%d%s", sign, randomDay, randomHour, randomMinute, randomSecond, millisString);
@@ -151,7 +151,7 @@ public void testHourToSecond() throws Exception {
151151
int randomSecond = randomInt(59);
152152

153153
boolean withMillis = randomBoolean();
154-
int randomMilli = withMillis ? randomInt(999999999) : 0;
154+
int randomMilli = withMillis ? randomInt(999) : 0;
155155
String millisString = withMillis ? "." + randomMilli : "";
156156

157157
String value = format(Locale.ROOT, "%s%d:%d:%d%s", sign, randomHour, randomMinute, randomSecond, millisString);
@@ -165,7 +165,7 @@ public void testMinuteToSecond() throws Exception {
165165
int randomSecond = randomInt(59);
166166

167167
boolean withMillis = randomBoolean();
168-
int randomMilli = withMillis ? randomInt(999999999) : 0;
168+
int randomMilli = withMillis ? randomInt(999) : 0;
169169
String millisString = withMillis ? "." + randomMilli : "";
170170

171171
String value = format(Locale.ROOT, "%s%d:%d%s", sign, randomMinute, randomSecond, millisString);
@@ -186,11 +186,11 @@ public void testYearToMonthTooBig() throws Exception {
186186

187187
public void testMillisTooBig() throws Exception {
188188
int randomSeconds = randomNonNegativeInt();
189-
int millisTooLarge = 1234567890;
189+
int millisTooLarge = 1234;
190190
String value = format(Locale.ROOT, "%s%d.%d", sign, randomSeconds, millisTooLarge);
191191
ParsingException pe = expectThrows(ParsingException.class, () -> parseInterval(EMPTY, value, INTERVAL_SECOND));
192192
assertEquals("line -1:0: Invalid [INTERVAL SECOND] value [" + value + "]: [MILLISECOND] unit has illegal value [" + millisTooLarge
193-
+ "], expected a positive number up to [999999999]", pe.getMessage());
193+
+ "], expected a positive number up to [999]", pe.getMessage());
194194
}
195195

196196
public void testDayToMinuteTooBig() throws Exception {

x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/parser/ExpressionTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void testStringInterval() throws Exception {
150150
int randomHour = randomInt(23);
151151
int randomMinute = randomInt(59);
152152
int randomSecond = randomInt(59);
153-
int randomMilli = randomInt(999999999);
153+
int randomMilli = randomInt(999);
154154

155155
String value = format(Locale.ROOT, "INTERVAL '%d %d:%d:%d.%d' DAY TO SECOND", randomDay, randomHour, randomMinute, randomSecond,
156156
randomMilli);
@@ -163,7 +163,7 @@ public void testNegativeStringInterval() throws Exception {
163163
int randomHour = randomInt(23);
164164
int randomMinute = randomInt(59);
165165
int randomSecond = randomInt(59);
166-
int randomMilli = randomInt(999999999);
166+
int randomMilli = randomInt(999);
167167

168168
String value = format(Locale.ROOT, "INTERVAL -'%d %d:%d:%d.%d' DAY TO SECOND", randomDay, randomHour, randomMinute, randomSecond,
169169
randomMilli);

0 commit comments

Comments
 (0)