|
@@ -31,6 +31,7 @@ import java.util.List;
|
|
|
import java.util.Locale;
|
|
|
import java.util.Map;
|
|
|
|
|
|
+import static org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument;
|
|
|
import static org.elasticsearch.ingest.common.ConvertProcessor.Type;
|
|
|
import static org.hamcrest.Matchers.containsString;
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
@@ -42,7 +43,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
|
|
|
int randomInt = randomInt();
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, randomInt);
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.INTEGER);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.INTEGER, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue(fieldName, Integer.class), equalTo(randomInt));
|
|
|
}
|
|
@@ -58,7 +59,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
expectedList.add(randomInt);
|
|
|
}
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.INTEGER);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.INTEGER, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
|
|
|
}
|
|
@@ -69,7 +70,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
String value = "string-" + randomAsciiOfLengthBetween(1, 10);
|
|
|
ingestDocument.setFieldValue(fieldName, value);
|
|
|
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.INTEGER);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.INTEGER, false);
|
|
|
try {
|
|
|
processor.execute(ingestDocument);
|
|
|
fail("processor execute should have failed");
|
|
@@ -85,7 +86,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, randomFloat);
|
|
|
expectedResult.put(fieldName, randomFloat);
|
|
|
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.FLOAT);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.FLOAT, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue(fieldName, Float.class), equalTo(randomFloat));
|
|
|
}
|
|
@@ -101,7 +102,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
expectedList.add(randomFloat);
|
|
|
}
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.FLOAT);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.FLOAT, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
|
|
|
}
|
|
@@ -112,7 +113,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
String value = "string-" + randomAsciiOfLengthBetween(1, 10);
|
|
|
ingestDocument.setFieldValue(fieldName, value);
|
|
|
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.FLOAT);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.FLOAT, false);
|
|
|
try {
|
|
|
processor.execute(ingestDocument);
|
|
|
fail("processor execute should have failed");
|
|
@@ -130,7 +131,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
}
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, booleanString);
|
|
|
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.BOOLEAN);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.BOOLEAN, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue(fieldName, Boolean.class), equalTo(randomBoolean));
|
|
|
}
|
|
@@ -150,7 +151,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
expectedList.add(randomBoolean);
|
|
|
}
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.BOOLEAN);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.BOOLEAN, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
|
|
|
}
|
|
@@ -167,7 +168,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
}
|
|
|
ingestDocument.setFieldValue(fieldName, fieldValue);
|
|
|
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.BOOLEAN);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.BOOLEAN, false);
|
|
|
try {
|
|
|
processor.execute(ingestDocument);
|
|
|
fail("processor execute should have failed");
|
|
@@ -201,7 +202,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
}
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
|
|
|
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.STRING);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.STRING, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(expectedFieldValue));
|
|
|
}
|
|
@@ -237,7 +238,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
expectedList.add(randomValueString);
|
|
|
}
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, fieldValue);
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.STRING);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, Type.STRING, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue(fieldName, List.class), equalTo(expectedList));
|
|
|
}
|
|
@@ -246,7 +247,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
|
|
String fieldName = RandomDocumentPicks.randomFieldName(random());
|
|
|
Type type = randomFrom(Type.values());
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, type);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, type, false);
|
|
|
try {
|
|
|
processor.execute(ingestDocument);
|
|
|
fail("processor execute should have failed");
|
|
@@ -258,7 +259,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
public void testConvertNullField() throws Exception {
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
|
|
|
Type type = randomFrom(Type.values());
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", type);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", type, false);
|
|
|
try {
|
|
|
processor.execute(ingestDocument);
|
|
|
fail("processor execute should have failed");
|
|
@@ -267,6 +268,25 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testConvertNonExistingFieldWithIgnoreMissing() throws Exception {
|
|
|
+ IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), new HashMap<>());
|
|
|
+ IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
+ String fieldName = RandomDocumentPicks.randomFieldName(random());
|
|
|
+ Type type = randomFrom(Type.values());
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, fieldName, type, true);
|
|
|
+ processor.execute(ingestDocument);
|
|
|
+ assertIngestDocument(originalIngestDocument, ingestDocument);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testConvertNullFieldWithIgnoreMissing() throws Exception {
|
|
|
+ IngestDocument originalIngestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", null));
|
|
|
+ IngestDocument ingestDocument = new IngestDocument(originalIngestDocument);
|
|
|
+ Type type = randomFrom(Type.values());
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", type, true);
|
|
|
+ processor.execute(ingestDocument);
|
|
|
+ assertIngestDocument(originalIngestDocument, ingestDocument);
|
|
|
+ }
|
|
|
+
|
|
|
public void testAutoConvertNotString() throws Exception {
|
|
|
Object randomValue;
|
|
|
switch(randomIntBetween(0, 2)) {
|
|
@@ -286,7 +306,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
throw new UnsupportedOperationException();
|
|
|
}
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", randomValue));
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
|
|
|
assertThat(convertedValue, sameInstance(randomValue));
|
|
@@ -295,7 +315,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
public void testAutoConvertStringNotMatched() throws Exception {
|
|
|
String value = "notAnIntFloatOrBool";
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", value));
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
|
|
|
assertThat(convertedValue, sameInstance(value));
|
|
@@ -306,7 +326,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
String booleanString = Boolean.toString(randomBoolean);
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(),
|
|
|
Collections.singletonMap("field", booleanString));
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
|
|
|
assertThat(convertedValue, equalTo(randomBoolean));
|
|
@@ -316,7 +336,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
int randomInt = randomInt();
|
|
|
String randomString = Integer.toString(randomInt);
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", randomString));
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
|
|
|
assertThat(convertedValue, equalTo(randomInt));
|
|
@@ -326,7 +346,7 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
float randomFloat = randomFloat();
|
|
|
String randomString = Float.toString(randomFloat);
|
|
|
IngestDocument ingestDocument = RandomDocumentPicks.randomIngestDocument(random(), Collections.singletonMap("field", randomString));
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), "field", "field", Type.AUTO, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
Object convertedValue = ingestDocument.getFieldValue("field", Object.class);
|
|
|
assertThat(convertedValue, equalTo(randomFloat));
|
|
@@ -337,10 +357,9 @@ public class ConvertProcessorTests extends ESTestCase {
|
|
|
int randomInt = randomInt();
|
|
|
String fieldName = RandomDocumentPicks.addRandomField(random(), ingestDocument, String.valueOf(randomInt));
|
|
|
String targetField = fieldName + randomAsciiOfLength(5);
|
|
|
- Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, targetField, Type.INTEGER);
|
|
|
+ Processor processor = new ConvertProcessor(randomAsciiOfLength(10), fieldName, targetField, Type.INTEGER, false);
|
|
|
processor.execute(ingestDocument);
|
|
|
assertThat(ingestDocument.getFieldValue(fieldName, String.class), equalTo(String.valueOf(randomInt)));
|
|
|
assertThat(ingestDocument.getFieldValue(targetField, Integer.class), equalTo(randomInt));
|
|
|
-
|
|
|
}
|
|
|
}
|