30
30
import java .util .List ;
31
31
import java .util .Map ;
32
32
33
+ import static org .elasticsearch .ingest .IngestDocumentMatcher .assertIngestDocument ;
33
34
import static org .hamcrest .Matchers .containsString ;
34
35
import static org .hamcrest .Matchers .equalTo ;
35
36
@@ -38,15 +39,15 @@ public class SplitProcessorTests extends ESTestCase {
38
39
public void testSplit () throws Exception {
39
40
IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
40
41
String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , "127.0.0.1" );
41
- Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), fieldName , "\\ ." );
42
+ Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), fieldName , "\\ ." , false );
42
43
processor .execute (ingestDocument );
43
44
assertThat (ingestDocument .getFieldValue (fieldName , List .class ), equalTo (Arrays .asList ("127" , "0" , "0" , "1" )));
44
45
}
45
46
46
47
public void testSplitFieldNotFound () throws Exception {
47
48
IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), new HashMap <>());
48
49
String fieldName = RandomDocumentPicks .randomFieldName (random ());
49
- Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), fieldName , "\\ ." );
50
+ Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), fieldName , "\\ ." , false );
50
51
try {
51
52
processor .execute (ingestDocument );
52
53
fail ("split processor should have failed" );
@@ -56,8 +57,9 @@ public void testSplitFieldNotFound() throws Exception {
56
57
}
57
58
58
59
public void testSplitNullValue () throws Exception {
59
- IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), Collections .singletonMap ("field" , null ));
60
- Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), "field" , "\\ ." );
60
+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (),
61
+ Collections .singletonMap ("field" , null ));
62
+ Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), "field" , "\\ ." , false );
61
63
try {
62
64
processor .execute (ingestDocument );
63
65
fail ("split processor should have failed" );
@@ -66,11 +68,29 @@ public void testSplitNullValue() throws Exception {
66
68
}
67
69
}
68
70
71
+ public void testSplitNullValueWithIgnoreMissing () throws Exception {
72
+ String fieldName = RandomDocumentPicks .randomFieldName (random ());
73
+ IngestDocument originalIngestDocument = RandomDocumentPicks .randomIngestDocument (random (),
74
+ Collections .singletonMap (fieldName , null ));
75
+ IngestDocument ingestDocument = new IngestDocument (originalIngestDocument );
76
+ Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), fieldName , "\\ ." , true );
77
+ processor .execute (ingestDocument );
78
+ assertIngestDocument (originalIngestDocument , ingestDocument );
79
+ }
80
+
81
+ public void testSplitNonExistentWithIgnoreMissing () throws Exception {
82
+ IngestDocument originalIngestDocument = RandomDocumentPicks .randomIngestDocument (random (), Collections .emptyMap ());
83
+ IngestDocument ingestDocument = new IngestDocument (originalIngestDocument );
84
+ Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), "field" , "\\ ." , true );
85
+ processor .execute (ingestDocument );
86
+ assertIngestDocument (originalIngestDocument , ingestDocument );
87
+ }
88
+
69
89
public void testSplitNonStringValue () throws Exception {
70
90
IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), new HashMap <>());
71
91
String fieldName = RandomDocumentPicks .randomFieldName (random ());
72
92
ingestDocument .setFieldValue (fieldName , randomInt ());
73
- Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), fieldName , "\\ ." );
93
+ Processor processor = new SplitProcessor (randomAsciiOfLength (10 ), fieldName , "\\ ." , false );
74
94
try {
75
95
processor .execute (ingestDocument );
76
96
fail ("split processor should have failed" );
0 commit comments