NIFI-5060 Updated SubstringAfter record processing to support multi-character search trimming

This closes #2623.

Signed-off-by: Mark Payne <markap14@hotmail.com>
This commit is contained in:
greencee 2018-04-09 15:28:54 -04:00 committed by Mark Payne
parent 88c079e447
commit fdea876ede
3 changed files with 4 additions and 2 deletions

View File

@ -58,7 +58,7 @@ public class SubstringAfter extends RecordPathSegment {
return new StandardFieldValue("", fv.getField(), fv.getParent().orElse(null));
}
return new StandardFieldValue(value.substring(index + 1), fv.getField(), fv.getParent().orElse(null));
return new StandardFieldValue(value.substring(index + searchValue.length()), fv.getField(), fv.getParent().orElse(null));
});
}

View File

@ -58,7 +58,7 @@ public class SubstringAfterLast extends RecordPathSegment {
return new StandardFieldValue("", fv.getField(), fv.getParent().orElse(null));
}
return new StandardFieldValue(value.substring(index + 1), fv.getField(), fv.getParent().orElse(null));
return new StandardFieldValue(value.substring(index + searchValue.length()), fv.getField(), fv.getParent().orElse(null));
});
}

View File

@ -849,10 +849,12 @@ public class TestRecordPath {
assertEquals("hn Doe", RecordPath.compile("substringAfter(/name, 'o')").evaluate(record).getSelectedFields().findFirst().get().getValue());
assertEquals("John Doe", RecordPath.compile("substringAfter(/name, 'XYZ')").evaluate(record).getSelectedFields().findFirst().get().getValue());
assertEquals("John Doe", RecordPath.compile("substringAfter(/name, '')").evaluate(record).getSelectedFields().findFirst().get().getValue());
assertEquals("n Doe", RecordPath.compile("substringAfter(/name, 'oh')").evaluate(record).getSelectedFields().findFirst().get().getValue());
assertEquals("e", RecordPath.compile("substringAfterLast(/name, 'o')").evaluate(record).getSelectedFields().findFirst().get().getValue());
assertEquals("John Doe", RecordPath.compile("substringAfterLast(/name, 'XYZ')").evaluate(record).getSelectedFields().findFirst().get().getValue());
assertEquals("John Doe", RecordPath.compile("substringAfterLast(/name, '')").evaluate(record).getSelectedFields().findFirst().get().getValue());
assertEquals("n Doe", RecordPath.compile("substringAfterLast(/name, 'oh')").evaluate(record).getSelectedFields().findFirst().get().getValue());
}
@Test