From fdea876ede6b503c703e9a816e9a29137be868f9 Mon Sep 17 00:00:00 2001 From: greencee Date: Mon, 9 Apr 2018 15:28:54 -0400 Subject: [PATCH] NIFI-5060 Updated SubstringAfter record processing to support multi-character search trimming This closes #2623. Signed-off-by: Mark Payne --- .../org/apache/nifi/record/path/functions/SubstringAfter.java | 2 +- .../apache/nifi/record/path/functions/SubstringAfterLast.java | 2 +- .../test/java/org/apache/nifi/record/path/TestRecordPath.java | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/SubstringAfter.java b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/SubstringAfter.java index 4bdd6b3f62..d883f2e153 100644 --- a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/SubstringAfter.java +++ b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/SubstringAfter.java @@ -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)); }); } diff --git a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/SubstringAfterLast.java b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/SubstringAfterLast.java index 71af1b9784..19e86a1c18 100644 --- a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/SubstringAfterLast.java +++ b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/SubstringAfterLast.java @@ -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)); }); } diff --git a/nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java b/nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java index dbf5fba46a..89b0893d2c 100644 --- a/nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java +++ b/nifi-commons/nifi-record-path/src/test/java/org/apache/nifi/record/path/TestRecordPath.java @@ -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