Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.1] Short circuit date patterns after first match (#83764) #84030

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/83764.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 83764
summary: Short circuit date patterns after first match
area: Ingest
type: bug
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public IngestDocument execute(IngestDocument ingestDocument) {
for (Function<Map<String, Object>, Function<String, ZonedDateTime>> dateParser : dateParsers) {
try {
dateTime = dateParser.apply(ingestDocument.getSourceAndMetadata()).apply(value);
break;
} catch (Exception e) {
// try the next parser and keep track of the exceptions
lastException = ExceptionsHelper.useOrSuppress(lastException, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,28 @@ public void testJavaPatternMultipleFormats() {
}
}

public void testShortCircuitAdditionalPatternsAfterFirstMatchingPattern() {
List<String> matchFormats = new ArrayList<>();
matchFormats.add("invalid");
matchFormats.add("uuuu-dd-MM");
matchFormats.add("uuuu-MM-dd");
DateProcessor dateProcessor = new DateProcessor(
randomAlphaOfLength(10),
null,
templatize(ZoneId.of("Europe/Amsterdam")),
templatize(Locale.ENGLISH),
"date_as_string",
matchFormats,
"date_as_date"
);

Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "2010-03-04");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-04-03T00:00:00.000+02:00"));
}

public void testJavaPatternNoTimezone() {
DateProcessor dateProcessor = new DateProcessor(
randomAlphaOfLength(10),
Expand Down