Skip to content

Commit d90e039

Browse files
authored
Fix ignore_missing in CsvProcessor (#51600) (#51610)
This change fixes inverted logic around ignore_missing in CsvProcessor
1 parent d77c3b2 commit d90e039

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/CsvProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public IngestDocument execute(IngestDocument ingestDocument) {
6868
}
6969

7070
String line = ingestDocument.getFieldValue(field, String.class, ignoreMissing);
71-
if (line == null && ignoreMissing == false) {
71+
if (line == null && ignoreMissing) {
7272
return ingestDocument;
7373
} else if (line == null) {
7474
throw new IllegalArgumentException("field [" + field + "] is null, cannot process it.");

modules/ingest-common/src/test/java/org/elasticsearch/ingest/common/CsvProcessorTests.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public void testEmptyFields() throws Exception {
158158
items.keySet().stream().skip(numItems - 1).forEach(key -> assertFalse(ingestDocument.hasField(key)));
159159
}
160160

161-
public void testWrongStings() throws Exception {
161+
public void testWrongStrings() throws Exception {
162162
assumeTrue("single run only", quote.isEmpty());
163163
expectThrows(IllegalArgumentException.class, () -> processDocument(new String[]{"a"}, "abc\"abc"));
164164
expectThrows(IllegalArgumentException.class, () -> processDocument(new String[]{"a"}, "\"abc\"asd"));
@@ -190,6 +190,19 @@ public void testUntrimmed() throws Exception {
190190
assertFalse(document.hasField("f"));
191191
}
192192

193+
public void testIgnoreMissing() {
194+
assumeTrue("single run only", quote.isEmpty());
195+
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
196+
String fieldName = randomAlphaOfLength(5);
197+
if (ingestDocument.hasField(fieldName)) {
198+
ingestDocument.removeField(fieldName);
199+
}
200+
CsvProcessor processor = new CsvProcessor(randomAlphaOfLength(5), fieldName, new String[]{"a"}, false, ',', '"', true);
201+
processor.execute(ingestDocument);
202+
CsvProcessor processor2 = new CsvProcessor(randomAlphaOfLength(5), fieldName, new String[]{"a"}, false, ',', '"', false);
203+
expectThrows(IllegalArgumentException.class, () -> processor2.execute(ingestDocument));
204+
}
205+
193206
public void testEmptyHeaders() throws Exception {
194207
assumeTrue("single run only", quote.isEmpty());
195208
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());

0 commit comments

Comments
 (0)