@@ -39,15 +39,15 @@ public class SplitProcessorTests extends ESTestCase {
3939 public void testSplit () throws Exception {
4040 IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
4141 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 );
4343 processor .execute (ingestDocument );
4444 assertThat (ingestDocument .getFieldValue (fieldName , List .class ), equalTo (Arrays .asList ("127" , "0" , "0" , "1" )));
4545 }
4646
4747 public void testSplitFieldNotFound () throws Exception {
4848 IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), new HashMap <>());
4949 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 );
5151 try {
5252 processor .execute (ingestDocument );
5353 fail ("split processor should have failed" );
@@ -59,7 +59,7 @@ public void testSplitFieldNotFound() throws Exception {
5959 public void testSplitNullValue () throws Exception {
6060 IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (),
6161 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" );
6363 try {
6464 processor .execute (ingestDocument );
6565 fail ("split processor should have failed" );
@@ -73,15 +73,15 @@ public void testSplitNullValueWithIgnoreMissing() throws Exception {
7373 IngestDocument originalIngestDocument = RandomDocumentPicks .randomIngestDocument (random (),
7474 Collections .singletonMap (fieldName , null ));
7575 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 );
7777 processor .execute (ingestDocument );
7878 assertIngestDocument (originalIngestDocument , ingestDocument );
7979 }
8080
8181 public void testSplitNonExistentWithIgnoreMissing () throws Exception {
8282 IngestDocument originalIngestDocument = RandomDocumentPicks .randomIngestDocument (random (), Collections .emptyMap ());
8383 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" );
8585 processor .execute (ingestDocument );
8686 assertIngestDocument (originalIngestDocument , ingestDocument );
8787 }
@@ -90,7 +90,7 @@ public void testSplitNonStringValue() throws Exception {
9090 IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random (), new HashMap <>());
9191 String fieldName = RandomDocumentPicks .randomFieldName (random ());
9292 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 );
9494 try {
9595 processor .execute (ingestDocument );
9696 fail ("split processor should have failed" );
@@ -121,8 +121,24 @@ public void testSplitWithTargetField() throws Exception {
121121 IngestDocument ingestDocument = RandomDocumentPicks .randomIngestDocument (random ());
122122 String fieldName = RandomDocumentPicks .addRandomField (random (), ingestDocument , "127.0.0.1" );
123123 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 );
125125 processor .execute (ingestDocument );
126126 assertThat (ingestDocument .getFieldValue (targetFieldName , List .class ), equalTo (Arrays .asList ("127" , "0" , "0" , "1" )));
127127 }
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+ }
128144}
0 commit comments