use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class DateProcessorTests method testJavaPatternLocale.
public void testJavaPatternLocale() {
assumeFalse("Can't run in a FIPS JVM, Joda parse date error", inFipsJvm());
DateProcessor dateProcessor = new DateProcessor(randomAlphaOfLength(10), null, templatize(ZoneId.of("Europe/Amsterdam")), templatize(Locale.ITALIAN), "date_as_string", Collections.singletonList("yyyy dd MMMM"), "date_as_date");
Map<String, Object> document = new HashMap<>();
document.put("date_as_string", "2010 12 giugno");
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), document);
dateProcessor.execute(ingestDocument);
assertThat(ingestDocument.getFieldValue("date_as_date", String.class), equalTo("2010-06-12T00:00:00.000+02:00"));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class DissectProcessorTests method testNullValueWithOutIgnoreMissing.
public void testNullValueWithOutIgnoreMissing() {
String fieldName = RandomDocumentPicks.randomFieldName(random());
Processor processor = new DissectProcessor("", null, fieldName, "%{a},%{b},%{c}", "", false);
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap(fieldName, null));
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
expectThrows(IllegalArgumentException.class, () -> processor.execute(ingestDocument));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class DissectProcessorTests method testNullValueWithIgnoreMissing.
public void testNullValueWithIgnoreMissing() throws Exception {
String fieldName = RandomDocumentPicks.randomFieldName(random());
Processor processor = new DissectProcessor("", null, fieldName, "%{a},%{b},%{c}", "", true);
IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap(fieldName, null));
IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
processor.execute(ingestDocument);
assertIngestDocument(originalIngestDocument, ingestDocument);
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class CsvProcessorTests method testQuotedStrings.
public void testQuotedStrings() {
assumeFalse("quote needed", quote.isEmpty());
int numItems = randomIntBetween(2, 10);
Map<String, String> items = new LinkedHashMap<>();
for (int i = 0; i < numItems; i++) {
items.put(randomAlphaOfLengthBetween(5, 10), separator + randomAlphaOfLengthBetween(5, 10) + separator + "\n\r" + randomAlphaOfLengthBetween(5, 10));
}
String[] headers = items.keySet().toArray(new String[numItems]);
String csv = items.values().stream().map(v -> quote + v + quote).collect(Collectors.joining(separator + ""));
IngestDocument ingestDocument = processDocument(headers, csv);
items.forEach((key, value) -> assertEquals(value.replace(quote + quote, quote), ingestDocument.getFieldValue(key, String.class)));
}
use of org.opensearch.ingest.IngestDocument in project OpenSearch by opensearch-project.
the class CsvProcessorTests method testIgnoreMissing.
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), null, fieldName, new String[] { "a" }, false, ',', '"', true, null);
processor.execute(ingestDocument);
CsvProcessor processor2 = new CsvProcessor(randomAlphaOfLength(5), null, fieldName, new String[] { "a" }, false, ',', '"', false, null);
expectThrows(IllegalArgumentException.class, () -> processor2.execute(ingestDocument));
}
Aggregations