From commits-return-44727-archive-asf-public=cust-asf.ponee.io@nifi.apache.org Fri Jun 4 15:56:42 2021 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mxout1-ec2-va.apache.org (mxout1-ec2-va.apache.org [3.227.148.255]) by mx-eu-01.ponee.io (Postfix) with ESMTPS id 682D118066B for ; Fri, 4 Jun 2021 17:56:42 +0200 (CEST) Received: from mail.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by mxout1-ec2-va.apache.org (ASF Mail Server at mxout1-ec2-va.apache.org) with SMTP id A153F3EDC6 for ; Fri, 4 Jun 2021 15:56:41 +0000 (UTC) Received: (qmail 84930 invoked by uid 500); 4 Jun 2021 15:56:41 -0000 Mailing-List: contact commits-help@nifi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@nifi.apache.org Delivered-To: mailing list commits@nifi.apache.org Received: (qmail 84921 invoked by uid 99); 4 Jun 2021 15:56:41 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 04 Jun 2021 15:56:41 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 1B6BC81A86; Fri, 4 Jun 2021 15:56:41 +0000 (UTC) Date: Fri, 04 Jun 2021 15:56:40 +0000 To: "commits@nifi.apache.org" Subject: [nifi] branch main updated: Rename RecordPath un/escape JSON functions (#5124) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <162282220040.10185.3058205148673210392@gitbox.apache.org> From: otto@apache.org X-Git-Host: gitbox.apache.org X-Git-Repo: nifi X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Oldrev: bc5204d4df8017cbde5f2d050d466cdb04e7f969 X-Git-Newrev: e883aa6b0be30ac18d7c2faa0bf01cbe7f5304bf X-Git-Rev: e883aa6b0be30ac18d7c2faa0bf01cbe7f5304bf X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated 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 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(){{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.