Skip to content

Commit

Permalink
Fix ignore_missing in CsvProcessor (#51600)
Browse files Browse the repository at this point in the history
This change fixes inverted logic around ignore_missing in CsvProcessor
  • Loading branch information
probakowski committed Jan 29, 2020
1 parent bd01cce commit 303ad97
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public IngestDocument execute(IngestDocument ingestDocument) {
}

String line = ingestDocument.getFieldValue(field, String.class, ignoreMissing);
if (line == null && ignoreMissing == false) {
if (line == null && ignoreMissing) {
return ingestDocument;
} else if (line == null) {
throw new IllegalArgumentException("field [" + field + "] is null, cannot process it.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public void testEmptyFields() throws Exception {
items.keySet().stream().skip(numItems - 1).forEach(key -> assertFalse(ingestDocument.hasField(key)));
}

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

public void testIgnoreMissing() {
assumeTrue("single run only", quote.isEmpty());
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
String fieldName = randomAlphaOfLength(5);
if (ingestDocument.hasField(fieldName)) {
ingestDocument.removeField(fieldName);
}
CsvProcessor processor = new CsvProcessor(randomAlphaOfLength(5), fieldName, new String[]{"a"}, false, ',', '"', true);
processor.execute(ingestDocument);
CsvProcessor processor2 = new CsvProcessor(randomAlphaOfLength(5), fieldName, new String[]{"a"}, false, ',', '"', false);
expectThrows(IllegalArgumentException.class, () -> processor2.execute(ingestDocument));
}

public void testEmptyHeaders() throws Exception {
assumeTrue("single run only", quote.isEmpty());
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
Expand Down

0 comments on commit 303ad97

Please sign in to comment.