Search in sources :

Example 51 with IngestDocument

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"));
}
Also used : HashMap(java.util.HashMap) IngestDocument(org.opensearch.ingest.IngestDocument) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 52 with IngestDocument

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));
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 53 with 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);
}
Also used : Processor(org.opensearch.ingest.Processor) IngestDocumentMatcher.assertIngestDocument(org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.opensearch.ingest.IngestDocument)

Example 54 with 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)));
}
Also used : LinkedHashMap(java.util.LinkedHashMap) Arrays(java.util.Arrays) ParametersFactory(com.carrotsearch.randomizedtesting.annotations.ParametersFactory) IngestDocument(org.opensearch.ingest.IngestDocument) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Map(java.util.Map) Name(com.carrotsearch.randomizedtesting.annotations.Name) HashMap(java.util.HashMap) RandomDocumentPicks(org.opensearch.ingest.RandomDocumentPicks) LinkedList(java.util.LinkedList) Collectors(java.util.stream.Collectors) IngestDocument(org.opensearch.ingest.IngestDocument) LinkedHashMap(java.util.LinkedHashMap)

Example 55 with IngestDocument

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));
}
Also used : IngestDocument(org.opensearch.ingest.IngestDocument)

Aggregations

IngestDocument (org.opensearch.ingest.IngestDocument)252 IngestDocumentMatcher.assertIngestDocument (org.opensearch.ingest.IngestDocumentMatcher.assertIngestDocument)150 Processor (org.opensearch.ingest.Processor)136 Matchers.containsString (org.hamcrest.Matchers.containsString)98 HashMap (java.util.HashMap)86 ArrayList (java.util.ArrayList)51 Map (java.util.Map)37 List (java.util.List)36 GeoIpCache (org.opensearch.ingest.geoip.IngestGeoIpPlugin.GeoIpCache)19 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)13 TestProcessor (org.opensearch.ingest.TestProcessor)12 SortOrder (org.opensearch.ingest.common.SortProcessor.SortOrder)12 Arrays (java.util.Arrays)11 Collectors (java.util.stream.Collectors)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 LinkedHashMap (java.util.LinkedHashMap)9 RandomDocumentPicks (org.opensearch.ingest.RandomDocumentPicks)9 Name (com.carrotsearch.randomizedtesting.annotations.Name)7 ParametersFactory (com.carrotsearch.randomizedtesting.annotations.ParametersFactory)7 LinkedList (java.util.LinkedList)7