nifi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject [nifi] branch main updated: Rename RecordPath un/escape JSON functions (#5124)
Date Fri, 04 Jun 2021 15:56:40 GMT
This is an automated email from the ASF dual-hosted git repository.

otto pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new e883aa6  Rename RecordPath un/escape JSON functions (#5124)
e883aa6 is described below

commit e883aa6b0be30ac18d7c2faa0bf01cbe7f5304bf
Author: Chris Sampson <12159006+ChrisSamo632@users.noreply.github.com>
AuthorDate: Fri Jun 4 16:56:28 2021 +0100

    Rename RecordPath un/escape JSON functions (#5124)
    
    Signed-off-by: Otto Fowler <ottobackwards@gmail.com>
    
    This closes #5124.
---
 .../functions/{JsonEscape.java => EscapeJson.java} |  6 ++---
 .../{JsonUnescape.java => UnescapeJson.java}       |  8 +++----
 .../nifi/record/path/paths/RecordPathCompiler.java | 12 +++++-----
 .../apache/nifi/record/path/TestRecordPath.java    | 26 +++++++++++-----------
 nifi-docs/src/main/asciidoc/record-path-guide.adoc | 14 ++++++------
 5 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/JsonEscape.java
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/EscapeJson.java
similarity index 94%
rename from nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/JsonEscape.java
rename to nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/EscapeJson.java
index b452c6c..461d3b8 100644
--- a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/JsonEscape.java
+++ b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/EscapeJson.java
@@ -30,13 +30,13 @@ import org.apache.nifi.serialization.record.util.DataTypeUtils;
 
 import java.util.stream.Stream;
 
-public class JsonEscape extends RecordPathSegment {
+public class EscapeJson extends RecordPathSegment {
     private final RecordPathSegment recordPath;
 
     private final ObjectMapper objectMapper = new ObjectMapper();
 
-    public JsonEscape(final RecordPathSegment recordPath, final boolean absolute) {
-        super("jsonEscape", null, absolute);
+    public EscapeJson(final RecordPathSegment recordPath, final boolean absolute) {
+        super("escapeJson", null, absolute);
         this.recordPath = recordPath;
     }
 
diff --git a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/JsonUnescape.java
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/UnescapeJson.java
similarity index 95%
rename from nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/JsonUnescape.java
rename to nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/UnescapeJson.java
index d16a280..6a18320 100644
--- a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/JsonUnescape.java
+++ b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/functions/UnescapeJson.java
@@ -34,13 +34,13 @@ import java.util.Arrays;
 import java.util.Map;
 import java.util.stream.Stream;
 
-public class JsonUnescape extends RecordPathSegment {
+public class UnescapeJson extends RecordPathSegment {
     private final RecordPathSegment recordPath;
 
     private final ObjectMapper objectMapper = new ObjectMapper();
 
-    public JsonUnescape(final RecordPathSegment recordPath, final boolean absolute) {
-        super("jsonUnescape", null, absolute);
+    public UnescapeJson(final RecordPathSegment recordPath, final boolean absolute) {
+        super("unescapeJson", null, absolute);
         this.recordPath = recordPath;
     }
 
@@ -63,7 +63,7 @@ public class JsonUnescape extends RecordPathSegment {
                             throw new RecordPathException("Unable to deserialise JSON String
into Record Path value", e);
                         }
                     } else {
-                        throw new IllegalArgumentException("Argument supplied to jsonUnescape
must be a String");
+                        throw new IllegalArgumentException("Argument supplied to unescapeJson
must be a String");
                     }
                 });
     }
diff --git a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
index cd46a40..7ef2255 100644
--- a/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
+++ b/nifi-commons/nifi-record-path/src/main/java/org/apache/nifi/record/path/paths/RecordPathCompiler.java
@@ -39,7 +39,7 @@ import org.apache.nifi.record.path.functions.Base64Decode;
 import org.apache.nifi.record.path.functions.Base64Encode;
 import org.apache.nifi.record.path.functions.Coalesce;
 import org.apache.nifi.record.path.functions.Concat;
-import org.apache.nifi.record.path.functions.JsonEscape;
+import org.apache.nifi.record.path.functions.EscapeJson;
 import org.apache.nifi.record.path.functions.FieldName;
 import org.apache.nifi.record.path.functions.Format;
 import org.apache.nifi.record.path.functions.Hash;
@@ -60,7 +60,7 @@ import org.apache.nifi.record.path.functions.ToString;
 import org.apache.nifi.record.path.functions.ToUpperCase;
 import org.apache.nifi.record.path.functions.TrimString;
 import org.apache.nifi.record.path.functions.UUID5;
-import org.apache.nifi.record.path.functions.JsonUnescape;
+import org.apache.nifi.record.path.functions.UnescapeJson;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -310,13 +310,13 @@ public class RecordPathCompiler {
                         final RecordPathSegment[] args = getArgPaths(argumentListTree, 1,
functionName, absolute);
                         return new Base64Decode(args[0], absolute);
                     }
-                    case "jsonEscape": {
+                    case "escapeJson": {
                         final RecordPathSegment[] args = getArgPaths(argumentListTree, 1,
functionName, absolute);
-                        return new JsonEscape(args[0], absolute);
+                        return new EscapeJson(args[0], absolute);
                     }
-                    case "jsonUnescape": {
+                    case "unescapeJson": {
                         final RecordPathSegment[] args = getArgPaths(argumentListTree, 1,
functionName, absolute);
-                        return new JsonUnescape(args[0], absolute);
+                        return new UnescapeJson(args[0], absolute);
                     }
                     case "hash":{
                         final RecordPathSegment[] args = getArgPaths(argumentListTree, 2,
functionName, absolute);
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 f5a105d..5a6057f 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
@@ -1647,7 +1647,7 @@ public class TestRecordPath {
     }
 
     @Test
-    public void testJsonEscape() {
+    public void testEscapeJson() {
         final RecordSchema address = new SimpleRecordSchema(Collections.singletonList(
                 new RecordField("address_1", RecordFieldType.STRING.getDataType())
         ));
@@ -1677,16 +1677,16 @@ public class TestRecordPath {
 
         final Record record = new MapRecord(schema, values);
 
-        assertEquals("\"John\"", RecordPath.compile("jsonEscape(/person/firstName)").evaluate(record).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue());
-        assertEquals("30", RecordPath.compile("jsonEscape(/person/age)").evaluate(record).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue());
+        assertEquals("\"John\"", RecordPath.compile("escapeJson(/person/firstName)").evaluate(record).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue());
+        assertEquals("30", RecordPath.compile("escapeJson(/person/age)").evaluate(record).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue());
         assertEquals(
                 "{\"firstName\":\"John\",\"age\":30,\"nicknames\":[\"J\",\"Johnny\"],\"addresses\":[{\"address_1\":\"123
Somewhere Street\"},{\"address_1\":\"456 Anywhere Road\"}]}",
-                RecordPath.compile("jsonEscape(/person)").evaluate(record).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue()
+                RecordPath.compile("escapeJson(/person)").evaluate(record).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue()
         );
     }
 
     @Test
-    public void testJsonUnescape() {
+    public void testUnescapeJson() {
         final RecordSchema address = new SimpleRecordSchema(Collections.singletonList(
                 new RecordField("address_1", RecordFieldType.STRING.getDataType())
         ));
@@ -1722,7 +1722,7 @@ public class TestRecordPath {
                             Collections.singletonMap("address_1", "456 Anywhere Road")
                     ));
                 }},
-                RecordPath.compile("jsonUnescape(/json_str)").evaluate(recordAddressesArray).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue()
+                RecordPath.compile("unescapeJson(/json_str)").evaluate(recordAddressesArray).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue()
         );
 
         // test CHOICE resulting in nested single RECORD
@@ -1738,28 +1738,28 @@ public class TestRecordPath {
                     put("nicknames", Arrays.asList("J", "Johnny"));
                     put("addresses", Collections.singletonMap("address_1", "123 Somewhere
Street"));
                 }},
-                RecordPath.compile("jsonUnescape(/json_str)").evaluate(recordAddressesSingle).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue()
+                RecordPath.compile("unescapeJson(/json_str)").evaluate(recordAddressesSingle).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue()
         );
 
         // test simple String field
         final Record recordJustName = new MapRecord(schema, Collections.singletonMap("json_str",
"{\"firstName\":\"John\"}"));
         assertEquals(
                 new HashMap<String, Object>(){{put("firstName", "John");}},
-                RecordPath.compile("jsonUnescape(/json_str)").evaluate(recordJustName).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue()
+                RecordPath.compile("unescapeJson(/json_str)").evaluate(recordJustName).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue()
         );
 
         // test simple String
         final Record recordJustString = new MapRecord(schema, Collections.singletonMap("json_str",
"\"John\""));
-        assertEquals("John", RecordPath.compile("jsonUnescape(/json_str)").evaluate(recordJustString).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue());
+        assertEquals("John", RecordPath.compile("unescapeJson(/json_str)").evaluate(recordJustString).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue());
 
         // test simple Int
         final Record recordJustInt = new MapRecord(schema, Collections.singletonMap("json_str",
"30"));
-        assertEquals(30, RecordPath.compile("jsonUnescape(/json_str)").evaluate(recordJustInt).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue());
+        assertEquals(30, RecordPath.compile("unescapeJson(/json_str)").evaluate(recordJustInt).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue());
 
         // test invalid JSON
         final Record recordInvalidJson = new MapRecord(schema, Collections.singletonMap("json_str",
"{\"invalid\": \"json"));
         try {
-            RecordPath.compile("jsonUnescape(/json_str)").evaluate(recordInvalidJson).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue();
+            RecordPath.compile("unescapeJson(/json_str)").evaluate(recordInvalidJson).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue();
             fail("Expected a RecordPathException for invalid JSON");
         } catch (RecordPathException rpe) {
             assertEquals("Unable to deserialise JSON String into Record Path value", rpe.getMessage());
@@ -1768,10 +1768,10 @@ public class TestRecordPath {
         // test not String
         final Record recordNotString = new MapRecord(schema, Collections.singletonMap("person",
new MapRecord(person, Collections.singletonMap("age", 30))));
         try {
-            RecordPath.compile("jsonUnescape(/person/age)").evaluate(recordNotString).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue();
+            RecordPath.compile("unescapeJson(/person/age)").evaluate(recordNotString).getSelectedFields().findFirst().orElseThrow(IllegalStateException::new).getValue();
             fail("Expected IllegalArgumentException for non-String input");
         } catch (IllegalArgumentException iae) {
-            assertEquals("Argument supplied to jsonUnescape must be a String", iae.getMessage());
+            assertEquals("Argument supplied to unescapeJson must be a String", iae.getMessage());
         }
     }
 
diff --git a/nifi-docs/src/main/asciidoc/record-path-guide.adoc b/nifi-docs/src/main/asciidoc/record-path-guide.adoc
index f75c2b5..5caa1ac 100644
--- a/nifi-docs/src/main/asciidoc/record-path-guide.adoc
+++ b/nifi-docs/src/main/asciidoc/record-path-guide.adoc
@@ -851,7 +851,7 @@ The following record path expression would decode the String using Base64:
 | `base64Decode(/name)` | John
 |==========================================================
 
-=== jsonEscape
+=== escapeJson
 
 JSON Stringifies a Record, Array or simple field (e.g. String), using the UTF-8 character
set. For example, given a schema such as:
 
@@ -885,12 +885,12 @@ The following record path expression would convert the record into an
escaped JS
 
 |==========================================================
 | RecordPath | Return value
-| `jsonEscape(/person)` | "{\"person\":{\"name\":\"John\",\"age\":30}}"
-| `jsonEscape(/person/firstName)` | "\"John\""
-| `jsonEscape(/person/age)` | "30"
+| `escapeJson(/person)` | "{\"person\":{\"name\":\"John\",\"age\":30}}"
+| `escapeJson(/person/firstName)` | "\"John\""
+| `escapeJson(/person/age)` | "30"
 |==========================================================
 
-=== jsonUnescape
+=== unescapeJson
 
 Converts a stringified JSON element to a Record, Array or simple field (e.g. String), using
the UTF-8 character set. For example, given a schema such as:
 
@@ -921,7 +921,7 @@ The following record path expression would populate the record with unescaped
JS
 
 |==========================================================
 | RecordPath | Return value
-| `jsonUnescape(/json_str)` | {"person": {"name": "John", "age": 30}}"
+| `unescapeJson(/json_str)` | {"person": {"name": "John", "age": 30}}"
 |==========================================================
 
 Given a record such as:
@@ -936,7 +936,7 @@ The following record path expression would return:
 
 |==========================================================
 | RecordPath | Return value
-| `jsonUnescape(/json_str)` | "John"
+| `unescapeJson(/json_str)` | "John"
 |==========================================================
 
 Note that the target schema must be pre-defined if the unescaped JSON is to be set in a Record's
fields - Infer Schema will not currently do this automatically.

Mime
View raw message