@@ -39,15 +39,15 @@ public class SplitProcessorTests extends ESTestCase {
39
39
public void testSplit () throws Exception {
40
40
IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
41
41
String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , "127.0.0.1" );
42
- Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , false , fieldName );
42
+ Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , false , false , fieldName );
43
43
processor .execute (ingestDocument );
44
44
assertThat (ingestDocument .getFieldValue (fieldName , List .class ), equalTo (Arrays .asList ("127" , "0" , "0" , "1" )));
45
45
}
46
46
47
47
public void testSplitFieldNotFound () throws Exception {
48
48
IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), new HashMap <>());
49
49
String fieldName = RandomDocumentPicks .randomFieldName (random ());
50
- Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , false , fieldName );
50
+ Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , false , false , fieldName );
51
51
try {
52
52
processor .execute (ingestDocument );
53
53
fail ("split processor should have failed" );
@@ -59,7 +59,7 @@ public void testSplitFieldNotFound() throws Exception {
59
59
public void testSplitNullValue () throws Exception {
60
60
IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (),
61
61
Collections .singletonMap ("field" , null ));
62
- Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), "field" , "\\ ." , false , "field" );
62
+ Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), "field" , "\\ ." , false , false , "field" );
63
63
try {
64
64
processor .execute (ingestDocument );
65
65
fail ("split processor should have failed" );
@@ -73,15 +73,15 @@ public void testSplitNullValueWithIgnoreMissing() throws Exception {
73
73
IngestDocument originalIngestDocument = RandomDocumentPicks .randomIngestDocument (random (),
74
74
Collections .singletonMap (fieldName , null ));
75
75
IngestDocument ingestDocument = new IngestDocument (originalIngestDocument );
76
- Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , true , fieldName );
76
+ Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , true , false , fieldName );
77
77
processor .execute (ingestDocument );
78
78
assertIngestDocument (originalIngestDocument , ingestDocument );
79
79
}
80
80
81
81
public void testSplitNonExistentWithIgnoreMissing () throws Exception {
82
82
IngestDocument originalIngestDocument = RandomDocumentPicks .randomIngestDocument (random (), Collections .emptyMap ());
83
83
IngestDocument ingestDocument = new IngestDocument (originalIngestDocument );
84
- Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), "field" , "\\ ." , true , "field" );
84
+ Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), "field" , "\\ ." , true , false , "field" );
85
85
processor .execute (ingestDocument );
86
86
assertIngestDocument (originalIngestDocument , ingestDocument );
87
87
}
@@ -90,7 +90,7 @@ public void testSplitNonStringValue() throws Exception {
90
90
IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), new HashMap <>());
91
91
String fieldName = RandomDocumentPicks .randomFieldName (random ());
92
92
ingestDocument .setFieldValue (fieldName , randomInt ());
93
- Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , false , fieldName );
93
+ Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , false , false , fieldName );
94
94
try {
95
95
processor .execute (ingestDocument );
96
96
fail ("split processor should have failed" );
@@ -121,8 +121,24 @@ public void testSplitWithTargetField() throws Exception {
121
121
IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
122
122
String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , "127.0.0.1" );
123
123
String targetFieldName = fieldName + randomAlphaOfLength (5 );
124
- Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , false , targetFieldName );
124
+ Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ ." , false , false , targetFieldName );
125
125
processor .execute (ingestDocument );
126
126
assertThat (ingestDocument .getFieldValue (targetFieldName , List .class ), equalTo (Arrays .asList ("127" , "0" , "0" , "1" )));
127
127
}
128
+
129
+ public void testSplitWithPreserveTrailing () throws Exception {
130
+ doTestSplitWithPreserveTrailing (true , "foo|bar|baz||" , Arrays .asList ("foo" , "bar" , "baz" , "" , "" ));
131
+ }
132
+
133
+ public void testSplitWithoutPreserveTrailing () throws Exception {
134
+ doTestSplitWithPreserveTrailing (false , "foo|bar|baz||" , Arrays .asList ("foo" , "bar" , "baz" ));
135
+ }
136
+
137
+ private void doTestSplitWithPreserveTrailing (boolean preserveTrailing , String fieldValue , List <String > expected ) throws Exception {
138
+ IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
139
+ String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , fieldValue );
140
+ Processor processor = new SplitProcessor (randomAlphaOfLength (10 ), fieldName , "\\ |" , false , preserveTrailing , fieldName );
141
+ processor .execute (ingestDocument );
142
+ assertThat (ingestDocument .getFieldValue (fieldName , List .class ), equalTo (expected ));
143
+ }
128
144
}
0 commit comments