Skip to content

Commit aba2282

Browse files
authored
Change year max digits for strict_date_optional_time and date_optional_time (#73034)
We changed the default joda behaviour in strict_date_optional_time to max 4 digits in a year. Java.time implementation should behave the same way. At the same time date_optional_time should have 9digits for year part. closes #52396 closes #72191
1 parent 450554a commit aba2282

File tree

16 files changed

+144
-69
lines changed

16 files changed

+144
-69
lines changed

client/rest-high-level/src/test/java/org/elasticsearch/client/ml/calendars/ScheduledEventTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
package org.elasticsearch.client.ml.calendars;
1010

1111
import org.elasticsearch.common.Nullable;
12+
import org.elasticsearch.common.time.DateUtils;
1213
import org.elasticsearch.common.xcontent.XContentParser;
1314
import org.elasticsearch.test.AbstractXContentTestCase;
1415

@@ -17,8 +18,9 @@
1718
public class ScheduledEventTests extends AbstractXContentTestCase<ScheduledEvent> {
1819

1920
public static ScheduledEvent testInstance(String calendarId, @Nullable String eventId) {
20-
Date start = new Date(randomNonNegativeLong());
21-
Date end = new Date(start.getTime() + randomIntBetween(1, 10000) * 1000);
21+
int duration = randomIntBetween(1, 10000) * 1000;
22+
Date start = new Date(randomLongBetween(1, DateUtils.MAX_MILLIS_BEFORE_9999) - duration );
23+
Date end = new Date(start.getTime() + duration);
2224

2325
return new ScheduledEvent(randomAlphaOfLength(10), start, end, calendarId, eventId);
2426
}

server/src/main/java/org/elasticsearch/common/time/DateFormatters.java

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,21 @@ public class DateFormatters {
5757
.toFormatter(Locale.ROOT)
5858
.withResolverStyle(ResolverStyle.STRICT);
5959

60+
private static final DateTimeFormatter STRICT_YEAR_MONTH_DAY_PRINTER = new DateTimeFormatterBuilder()
61+
.appendValue(ChronoField.YEAR, 4, 9, SignStyle.EXCEEDS_PAD)
62+
.optionalStart()
63+
.appendLiteral("-")
64+
.appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE)
65+
.optionalStart()
66+
.appendLiteral('-')
67+
.appendValue(DAY_OF_MONTH, 2, 2, SignStyle.NOT_NEGATIVE)
68+
.optionalEnd()
69+
.optionalEnd()
70+
.toFormatter(Locale.ROOT)
71+
.withResolverStyle(ResolverStyle.STRICT);
72+
6073
private static final DateTimeFormatter STRICT_YEAR_MONTH_DAY_FORMATTER = new DateTimeFormatterBuilder()
61-
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
74+
.appendValue(ChronoField.YEAR, 4, 4, SignStyle.EXCEEDS_PAD)
6275
.optionalStart()
6376
.appendLiteral("-")
6477
.appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE)
@@ -81,7 +94,7 @@ public class DateFormatters {
8194
.withResolverStyle(ResolverStyle.STRICT);
8295

8396
private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_PRINTER = new DateTimeFormatterBuilder()
84-
.append(STRICT_YEAR_MONTH_DAY_FORMATTER)
97+
.append(STRICT_YEAR_MONTH_DAY_PRINTER)
8598
.appendLiteral('T')
8699
.optionalStart()
87100
.appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE)
@@ -164,7 +177,7 @@ public class DateFormatters {
164177
.withResolverStyle(ResolverStyle.STRICT);
165178

166179
private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_PRINTER_NANOS = new DateTimeFormatterBuilder()
167-
.append(STRICT_YEAR_MONTH_DAY_FORMATTER)
180+
.append(STRICT_YEAR_MONTH_DAY_PRINTER)
168181
.appendLiteral('T')
169182
.optionalStart()
170183
.appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE)
@@ -576,7 +589,7 @@ public class DateFormatters {
576589
*/
577590
private static final DateFormatter STRICT_YEAR_MONTH = new JavaDateFormatter("strict_year_month",
578591
new DateTimeFormatterBuilder()
579-
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
592+
.appendValue(ChronoField.YEAR, 4, 4, SignStyle.EXCEEDS_PAD)
580593
.appendLiteral("-")
581594
.appendValue(MONTH_OF_YEAR, 2, 2, SignStyle.NOT_NEGATIVE)
582595
.toFormatter(Locale.ROOT)
@@ -586,7 +599,7 @@ public class DateFormatters {
586599
* A strict formatter that formats or parses a year, such as '2011'.
587600
*/
588601
private static final DateFormatter STRICT_YEAR = new JavaDateFormatter("strict_year", new DateTimeFormatterBuilder()
589-
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
602+
.appendValue(ChronoField.YEAR, 4, 4, SignStyle.EXCEEDS_PAD)
590603
.toFormatter(Locale.ROOT)
591604
.withResolverStyle(ResolverStyle.STRICT));
592605

@@ -628,7 +641,7 @@ public class DateFormatters {
628641
);
629642

630643
private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_NO_MILLIS_BASE = new DateTimeFormatterBuilder()
631-
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
644+
.appendValue(ChronoField.YEAR, 4, 4, SignStyle.EXCEEDS_PAD)
632645
.appendLiteral('-')
633646
.appendValue(DAY_OF_YEAR, 3, 3, SignStyle.NOT_NEGATIVE)
634647
.appendLiteral('T')
@@ -759,7 +772,7 @@ public class DateFormatters {
759772
new JavaDateFormatter("strict_hour_minute", DateTimeFormatter.ofPattern("HH:mm", Locale.ROOT));
760773

761774
private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_PRINTER = new DateTimeFormatterBuilder()
762-
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
775+
.appendValue(ChronoField.YEAR, 4, 4, SignStyle.EXCEEDS_PAD)
763776
.appendLiteral('-')
764777
.appendValue(DAY_OF_YEAR, 3, 3, SignStyle.NOT_NEGATIVE)
765778
.appendLiteral('T')
@@ -773,7 +786,7 @@ public class DateFormatters {
773786
.withResolverStyle(ResolverStyle.STRICT);
774787

775788
private static final DateTimeFormatter STRICT_ORDINAL_DATE_TIME_FORMATTER_BASE = new DateTimeFormatterBuilder()
776-
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
789+
.appendValue(ChronoField.YEAR, 4, 4, SignStyle.EXCEEDS_PAD)
777790
.appendLiteral('-')
778791
.appendValue(DAY_OF_YEAR, 3, 3, SignStyle.NOT_NEGATIVE)
779792
.appendLiteral('T')
@@ -1014,7 +1027,7 @@ public class DateFormatters {
10141027

10151028
private static final DateTimeFormatter STRICT_ORDINAL_DATE_FORMATTER = new DateTimeFormatterBuilder()
10161029
.parseCaseInsensitive()
1017-
.appendValue(ChronoField.YEAR, 4, 10, SignStyle.EXCEEDS_PAD)
1030+
.appendValue(ChronoField.YEAR, 4, 4, SignStyle.EXCEEDS_PAD)
10181031
.appendLiteral('-')
10191032
.appendValue(DAY_OF_YEAR, 3)
10201033
.optionalStart()
@@ -1040,7 +1053,7 @@ public class DateFormatters {
10401053
/////////////////////////////////////////
10411054

10421055
private static final DateTimeFormatter DATE_FORMATTER = new DateTimeFormatterBuilder()
1043-
.appendValue(ChronoField.YEAR, 1, 5, SignStyle.NORMAL)
1056+
.appendValue(ChronoField.YEAR, 1, 9, SignStyle.NORMAL)
10441057
.optionalStart()
10451058
.appendLiteral('-')
10461059
.appendValue(MONTH_OF_YEAR, 1, 2, SignStyle.NOT_NEGATIVE)

server/src/main/java/org/elasticsearch/common/time/DateUtils.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import static org.elasticsearch.common.time.DateUtilsRounding.utcMillisAtStartOfYear;
3131

3232
public class DateUtils {
33+
public static final long MAX_MILLIS_BEFORE_9999 = 253402300799999L; // end of year 9999
34+
public static final long MAX_MILLIS_BEFORE_MINUS_9999 = -377705116800000L; // beginning of year -9999
35+
3336
public static DateTimeZone zoneIdToDateTimeZone(ZoneId zoneId) {
3437
if (zoneId == null) {
3538
return null;

server/src/test/java/org/elasticsearch/common/joda/JavaJodaTimeDuellingTests.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.joda.time.DateTime;
2020
import org.joda.time.DateTimeZone;
2121
import org.joda.time.format.ISODateTimeFormat;
22+
import org.junit.Assert;
2223
import org.junit.BeforeClass;
2324

2425
import java.time.Instant;
@@ -50,6 +51,18 @@ public void testIncorrectFormat() {
5051
assertParseException("2021-01-01T23-35-00Z", "strict_date_optional_time");
5152
}
5253

54+
public void testMinMillis() {
55+
String jodaFormatted = Joda.forPattern("strict_date_optional_time").formatMillis(Long.MIN_VALUE);
56+
String javaFormatted = DateFormatter.forPattern("strict_date_optional_time").formatMillis(Long.MIN_VALUE);
57+
Assert.assertEquals(jodaFormatted, javaFormatted);
58+
}
59+
public void testYearParsing() {
60+
//this one is considered a year
61+
assertSameDate("1234", "strict_date_optional_time||epoch_millis");
62+
//this one is considered a 12345milliseconds since epoch
63+
assertSameDate("12345", "strict_date_optional_time||epoch_millis");
64+
}
65+
5366
public void testTimezoneParsing() {
5467
/** this testcase won't work in joda. See comment in {@link #testPartialTimeParsing()}
5568
* assertSameDateAs("2016-11-30T+01", "strict_date_optional_time", "strict_date_optional_time");

server/src/test/java/org/elasticsearch/common/time/DateFormattersTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public void testEpochMillisParser() {
8484
public void testPrintersLongMinMaxValue() {
8585
for (FormatNames format : FormatNames.values()) {
8686
DateFormatter formatter = DateFormatters.forPattern(format.getName());
87-
formatter.format(DateFieldMapper.Resolution.MILLISECONDS.toInstant(Long.MIN_VALUE));
88-
formatter.format(DateFieldMapper.Resolution.MILLISECONDS.toInstant(Long.MAX_VALUE));
87+
formatter.format(DateFieldMapper.Resolution.MILLISECONDS.toInstant(DateUtils.MAX_MILLIS_BEFORE_9999));
88+
formatter.format(DateFieldMapper.Resolution.MILLISECONDS.toInstant(DateUtils.MAX_MILLIS_BEFORE_MINUS_9999));
8989
}
9090
}
9191

server/src/test/java/org/elasticsearch/common/time/JavaDateMathParserTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,10 @@ public void testTimestamps() {
306306
long datetime = parser.parse("1418248078", () -> 0).toEpochMilli();
307307
assertDateEquals(datetime, "1418248078", "2014-12-10T21:47:58.000");
308308

309-
// a timestamp before 100000 is a year
309+
// for date_optional_time a timestamp with more than 9digits is epoch
310310
assertDateMathEquals("9999", "9999-01-01T00:00:00.000");
311311
assertDateMathEquals("10000", "10000-01-01T00:00:00.000");
312-
assertDateMathEquals("100000", "1970-01-01T00:01:40.000");
312+
assertDateMathEquals("1000000000", "1970-01-12T13:46:40.000Z");
313313

314314
// but 10000 with T is still a date format
315315
assertDateMathEquals("10000-01-01T", "10000-01-01T00:00:00.000");

server/src/test/java/org/elasticsearch/index/mapper/DateFieldMapperTests.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,15 +134,17 @@ public void testStore() throws Exception {
134134

135135
public void testIgnoreMalformed() throws IOException {
136136
testIgnoreMalformedForValue("2016-03-99",
137-
"failed to parse date field [2016-03-99] with format [strict_date_optional_time||epoch_millis]");
137+
"failed to parse date field [2016-03-99] with format [strict_date_optional_time||epoch_millis]",
138+
"strict_date_optional_time||epoch_millis");
138139
testIgnoreMalformedForValue("-2147483648",
139-
"Invalid value for Year (valid values -999999999 - 999999999): -2147483648");
140-
testIgnoreMalformedForValue("-522000000", "long overflow");
140+
"failed to parse date field [-2147483648] with format [strict_date_optional_time||epoch_millis]",
141+
"strict_date_optional_time||epoch_millis");
142+
testIgnoreMalformedForValue("-522000000", "long overflow", "date_optional_time");
141143
}
142144

143-
private void testIgnoreMalformedForValue(String value, String expectedCause) throws IOException {
145+
private void testIgnoreMalformedForValue(String value, String expectedCause, String dateFormat) throws IOException {
144146

145-
DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping));
147+
DocumentMapper mapper = createDocumentMapper(fieldMapping((builder)-> dateFieldMapping(builder, dateFormat)));
146148

147149
MapperParsingException e = expectThrows(MapperParsingException.class,
148150
() -> mapper.parse(source(b -> b.field("field", value))));
@@ -152,6 +154,7 @@ private void testIgnoreMalformedForValue(String value, String expectedCause) thr
152154

153155
DocumentMapper mapper2 = createDocumentMapper(fieldMapping(b -> b
154156
.field("type", "date")
157+
.field("format", dateFormat)
155158
.field("ignore_malformed", true)));
156159

157160
ParsedDocument doc = mapper2.parse(source(b -> b.field("field", value)));
@@ -161,6 +164,11 @@ private void testIgnoreMalformedForValue(String value, String expectedCause) thr
161164
assertArrayEquals(new String[] { "field" }, TermVectorsService.getValues(doc.rootDoc().getFields("_ignored")));
162165
}
163166

167+
private void dateFieldMapping(XContentBuilder builder, String dateFormat) throws IOException {
168+
builder.field("type", "date");
169+
builder.field("format", dateFormat);
170+
171+
}
164172
public void testChangeFormat() throws IOException {
165173

166174
DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b

server/src/test/java/org/elasticsearch/search/aggregations/bucket/histogram/LongBoundsTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.common.time.DateFormatter;
15+
import org.elasticsearch.common.time.DateUtils;
1516
import org.elasticsearch.common.xcontent.ToXContent;
1617
import org.elasticsearch.common.xcontent.XContentBuilder;
1718
import org.elasticsearch.common.xcontent.XContentParser;
@@ -44,8 +45,8 @@ public static LongBounds randomExtendedBounds() {
4445
* Construct a random {@link LongBounds} in pre-parsed form.
4546
*/
4647
public static LongBounds randomParsedExtendedBounds() {
47-
long maxDateValue = 253402300799999L; // end of year 9999
48-
long minDateValue = -377705116800000L; // beginning of year -9999
48+
long maxDateValue = DateUtils.MAX_MILLIS_BEFORE_9999;
49+
long minDateValue = DateUtils.MAX_MILLIS_BEFORE_MINUS_9999; // beginning of year -9999
4950
if (randomBoolean()) {
5051
// Construct with one missing bound
5152
if (randomBoolean()) {

test/framework/src/main/java/org/elasticsearch/test/ESTestCase.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,13 @@ public static DateTimeZone randomDateTimeZone() {
863863
return DateTimeZone.forID(randomFrom(JODA_TIMEZONE_IDS));
864864
}
865865

866+
/**
867+
* generate a random epoch millis in a range 1 to 9999-12-31T23:59:59.999
868+
*/
869+
public long randomMillisUpToYear9999() {
870+
return randomLongBetween(1, DateUtils.MAX_MILLIS_BEFORE_9999);
871+
}
872+
866873
/**
867874
* generate a random TimeZone from the ones available in java.util
868875
*/

x-pack/plugin/analytics/src/test/java/org/elasticsearch/xpack/analytics/topmetrics/InternalTopMetricsTests.java

Lines changed: 41 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.elasticsearch.common.ParseField;
1313
import org.elasticsearch.common.Strings;
1414
import org.elasticsearch.common.time.DateFormatter;
15+
import org.elasticsearch.common.time.DateUtils;
1516
import org.elasticsearch.common.util.CollectionUtils;
1617
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
1718
import org.elasticsearch.index.mapper.DateFieldMapper;
@@ -35,6 +36,7 @@
3536
import java.util.List;
3637
import java.util.Map;
3738
import java.util.Set;
39+
import java.util.function.Function;
3840
import java.util.function.Predicate;
3941
import java.util.function.Supplier;
4042
import java.util.stream.IntStream;
@@ -263,15 +265,18 @@ protected List<NamedXContentRegistry.Entry> getNamedXContents() {
263265

264266
@Override
265267
protected InternalTopMetrics createTestInstance(String name, Map<String, Object> metadata) {
266-
return createTestInstance(name, metadata, InternalAggregationTestCase::randomNumericDocValueFormat);
268+
return createTestInstance(name, metadata, InternalAggregationTestCase::randomNumericDocValueFormat,
269+
InternalTopMetricsTests::randomSortValue);
267270
}
268271

269272
private InternalTopMetrics createTestInstance(String name,
270-
Map<String, Object> metadata, Supplier<DocValueFormat> randomDocValueFormat) {
273+
Map<String, Object> metadata, Supplier<DocValueFormat> randomDocValueFormat,
274+
Function<DocValueFormat,SortValue> sortValueSupplier) {
271275
int metricCount = between(1, 5);
272276
List<String> metricNames = randomMetricNames(metricCount);
273277
int size = between(1, 100);
274-
List<InternalTopMetrics.TopMetric> topMetrics = randomTopMetrics(randomDocValueFormat, between(0, size), metricCount);
278+
List<InternalTopMetrics.TopMetric> topMetrics = randomTopMetrics(randomDocValueFormat, between(0, size), metricCount,
279+
sortValueSupplier);
275280
return new InternalTopMetrics(name, sortOrder, metricNames, size, topMetrics, metadata);
276281
}
277282

@@ -301,7 +306,8 @@ protected InternalTopMetrics mutateInstance(InternalTopMetrics instance) throws
301306
int fixedSize = size;
302307
int fixedMetricsSize = metricNames.size();
303308
topMetrics = randomValueOtherThan(topMetrics, () -> randomTopMetrics(
304-
InternalAggregationTestCase::randomNumericDocValueFormat, between(1, fixedSize), fixedMetricsSize));
309+
InternalAggregationTestCase::randomNumericDocValueFormat, between(1, fixedSize), fixedMetricsSize,
310+
InternalTopMetricsTests::randomSortValue));
305311
break;
306312
default:
307313
throw new IllegalArgumentException("bad mutation");
@@ -315,7 +321,8 @@ protected InternalTopMetrics mutateInstance(InternalTopMetrics instance) throws
315321
* implement {@link Object#equals(Object)}.
316322
*/
317323
public void testFromXContentDates() throws IOException {
318-
InternalTopMetrics aggregation = createTestInstance(randomAlphaOfLength(3), emptyMap(), InternalTopMetricsTests::strictDateTime);
324+
InternalTopMetrics aggregation = createTestInstance(randomAlphaOfLength(3),
325+
emptyMap(), InternalTopMetricsTests::strictDateTime, InternalTopMetricsTests::randomSortValue);
319326
ParsedAggregation parsedAggregation = parseAndAssert(aggregation, randomBoolean(), randomBoolean());
320327
assertFromXContent(aggregation, parsedAggregation);
321328
}
@@ -359,7 +366,8 @@ protected List<InternalTopMetrics> randomResultsToReduce(String name, int count)
359366
randomTopMetrics(
360367
InternalAggregationTestCase::randomNumericDocValueFormat,
361368
between(0, prototype.getSize()),
362-
prototype.getMetricNames().size()
369+
prototype.getMetricNames().size(),
370+
InternalTopMetricsTests::randomSortValue
363371
),
364372
prototype.getMetadata()
365373
)
@@ -381,12 +389,16 @@ protected void assertReduced(InternalTopMetrics reduced, List<InternalTopMetrics
381389
assertThat(reduced.getTopMetrics(), equalTo(winners));
382390
}
383391

384-
private List<InternalTopMetrics.TopMetric> randomTopMetrics(
385-
Supplier<DocValueFormat> randomDocValueFormat, int length, int metricCount) {
392+
private List<InternalTopMetrics.TopMetric> randomTopMetrics(Supplier<DocValueFormat> randomDocValueFormat, int length, int metricCount,
393+
Function<DocValueFormat,SortValue> sortValueSupplier) {
386394
return IntStream.range(0, length)
387-
.mapToObj(i -> new InternalTopMetrics.TopMetric(
388-
randomDocValueFormat.get(), randomSortValue(), randomMetricValues(randomDocValueFormat, metricCount)
389-
))
395+
.mapToObj(i -> {
396+
DocValueFormat docValueFormat = randomDocValueFormat.get();
397+
return new InternalTopMetrics.TopMetric(
398+
docValueFormat, sortValueSupplier.apply(docValueFormat),
399+
randomMetricValues(randomDocValueFormat, metricCount, sortValueSupplier)
400+
);
401+
})
390402
.sorted((lhs, rhs) -> sortOrder.reverseMul() * lhs.getSortValue().compareTo(rhs.getSortValue()))
391403
.collect(toList());
392404
}
@@ -399,9 +411,13 @@ static List<String> randomMetricNames(int metricCount) {
399411
return new ArrayList<>(names);
400412
}
401413

402-
private List<InternalTopMetrics.MetricValue> randomMetricValues(Supplier<DocValueFormat> randomDocValueFormat, int metricCount) {
414+
private List<InternalTopMetrics.MetricValue> randomMetricValues(Supplier<DocValueFormat> randomDocValueFormat, int metricCount,
415+
Function<DocValueFormat,SortValue> sortValueSupplier) {
403416
return IntStream.range(0, metricCount)
404-
.mapToObj(i -> new InternalTopMetrics.MetricValue(randomDocValueFormat.get(), randomSortValue()))
417+
.mapToObj(i -> {
418+
DocValueFormat format = randomDocValueFormat.get();
419+
return new InternalTopMetrics.MetricValue(format, sortValueSupplier.apply(format));
420+
})
405421
.collect(toList());
406422
}
407423

@@ -418,6 +434,18 @@ private static SortValue randomSortValue() {
418434
return SortValue.from(randomDouble());
419435
}
420436

437+
private static SortValue randomSortValue(DocValueFormat docValueFormat) {
438+
if(docValueFormat instanceof DocValueFormat.DateTime){
439+
if (randomBoolean()) {
440+
return SortValue.from(randomLongBetween(DateUtils.MAX_MILLIS_BEFORE_MINUS_9999, DateUtils.MAX_MILLIS_BEFORE_9999));
441+
}
442+
return SortValue.from(
443+
randomDoubleBetween(DateUtils.MAX_MILLIS_BEFORE_MINUS_9999, DateUtils.MAX_MILLIS_BEFORE_9999, true));
444+
}
445+
return randomSortValue();
446+
}
447+
448+
421449
@Override
422450
protected Predicate<String> excludePathsFromXContentInsertion() {
423451
return path -> path.endsWith(".metrics");

0 commit comments

Comments
 (0)