You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by mattyb149 <gi...@git.apache.org> on 2018/04/17 18:09:14 UTC

[GitHub] nifi pull request #2640: NIFI-4456: Support multiple JSON objects in JSON re...

GitHub user mattyb149 opened a pull request:

    https://github.com/apache/nifi/pull/2640

    NIFI-4456: Support multiple JSON objects in JSON record reader/writers

    Thank you for submitting a contribution to Apache NiFi.
    
    In order to streamline the review of the contribution we ask you
    to ensure the following steps have been taken:
    
    ### For all changes:
    - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
         in the commit message?
    
    - [x] Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.
    
    - [x] Has your PR been rebased against the latest commit within the target branch (typically master)?
    
    - [x] Is your initial contribution a single, squashed commit?
    
    ### For code changes:
    - [x] Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
    - [x] Have you written or updated unit tests to verify your changes?
    - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
    - [ ] If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
    - [ ] If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
    - [x] If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?
    
    ### For documentation related changes:
    - [x] Have you ensured that format looks appropriate for the output in which it is rendered?
    
    ### Note:
    Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/mattyb149/nifi NIFI-4456

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/nifi/pull/2640.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2640
    
----
commit 16ca567ea25e931679ca6f81ff020a94ab7be32d
Author: Matthew Burgess <ma...@...>
Date:   2018-04-17T15:04:56Z

    NIFI-4456: Support multiple JSON objects in JSON record reader/writers

----


---

[GitHub] nifi pull request #2640: NIFI-4456: Support multiple JSON objects in JSON re...

Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2640#discussion_r183161985
  
    --- Diff: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/JsonTreeReader.java ---
    @@ -39,11 +39,11 @@
     
     @Tags({"json", "tree", "record", "reader", "parser"})
     @CapabilityDescription("Parses JSON into individual Record objects. The Record that is produced will contain all top-level "
    -    + "elements of the corresponding JSON Object. "
    -    + "The root JSON element can be either a single element or an array of JSON elements, and each "
    -    + "element in that array will be treated as a separate record. "
    -    + "If the schema that is configured contains a field that is not present in the JSON, a null value will be used. If the JSON contains "
    -    + "a field that is not present in the schema, that field will be skipped. "
    +        + "elements of the corresponding JSON Objects. The reader does not require the flow file content to be well-formed JSON; rather "
    --- End diff --
    
    I would make the same comment here as above, regarding the phrasing that the flow file content need not be well-formed JSON.


---

[GitHub] nifi pull request #2640: NIFI-4456: Support multiple JSON objects in JSON re...

Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2640#discussion_r183161782
  
    --- Diff: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/JsonRecordSetWriter.java ---
    @@ -64,18 +72,40 @@
             .defaultValue("false")
             .required(true)
             .build();
    +    static final PropertyDescriptor OUTPUT_GROUPING = new PropertyDescriptor.Builder()
    +            .name("output-grouping")
    +            .displayName("Output Grouping")
    +            .description("Specifies how the writer should output the JSON records (as an array or one object per line, e.g.) Note that if 'One Line Per Object' is "
    +                    + "selected, then Pretty Print JSON must be false.")
    +            .allowableValues(OUTPUT_ARRAY, OUTPUT_ONELINE)
    +            .defaultValue(OUTPUT_ARRAY.getValue())
    +            .required(true)
    +            .build();
     
         private volatile boolean prettyPrint;
         private volatile NullSuppression nullSuppression;
    +    private volatile OutputGrouping outputGrouping;
     
         @Override
         protected List<PropertyDescriptor> getSupportedPropertyDescriptors() {
             final List<PropertyDescriptor> properties = new ArrayList<>(super.getSupportedPropertyDescriptors());
             properties.add(PRETTY_PRINT_JSON);
             properties.add(SUPPRESS_NULLS);
    +        properties.add(OUTPUT_GROUPING);
             return properties;
         }
     
    +    @Override
    +    protected Collection<ValidationResult> customValidate(ValidationContext context) {
    +        final List<ValidationResult> problems = new ArrayList<>(super.customValidate(context));
    +        // Don't allow Pretty Print if One Line Per Object is selected
    +        if (context.getProperty(PRETTY_PRINT_JSON).asBoolean() && context.getProperty(OUTPUT_GROUPING).getValue().equals(OUTPUT_ONELINE.getValue())) {
    +            problems.add(new ValidationResult.Builder().input("Pretty Print").valid(false)
    +                    .explanation("Pretty Print JSON must be false when One Line Per Object is selected").build());
    --- End diff --
    
    Would recommend phrasing it something like "... when 'Output Grouping' is set to 'One Line Per Object'" to provide additional clarity


---

[GitHub] nifi pull request #2640: NIFI-4456: Support multiple JSON objects in JSON re...

Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2640#discussion_r183159695
  
    --- Diff: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/AbstractJsonRowRecordReader.java ---
    @@ -197,7 +193,8 @@ private JsonNode getNextJsonNode() throws JsonParseException, IOException, Malfo
                         return jsonParser.readValueAsTree();
                     case END_ARRAY:
                     case START_ARRAY:
    -                    return null;
    +                    return getNextJsonNode();
    --- End diff --
    
    Would recommend that we just use 'continue' here as we do for END_OBJECT, rather than recursively calling ourselves. Is consistent and avoids unnecessarily deepening the stack, but will result in the same logic being evaluated


---

[GitHub] nifi pull request #2640: NIFI-4456: Support multiple JSON objects in JSON re...

Posted by markap14 <gi...@git.apache.org>.
Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/2640#discussion_r183161097
  
    --- Diff: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/json/JsonPathReader.java ---
    @@ -48,15 +48,17 @@
     import com.jayway.jsonpath.JsonPath;
     
     @Tags({"json", "jsonpath", "record", "reader", "parser"})
    -@CapabilityDescription("Parses JSON records and evaluates user-defined JSON Path's against each JSON object. The root element may be either "
    -    + "a single JSON object or a JSON array. If a JSON array is found, each JSON object within that array is treated as a separate record. "
    -    + "User-defined properties define the fields that should be extracted from the JSON in order to form the fields of a Record. Any JSON field "
    -    + "that is not extracted via a JSONPath will not be returned in the JSON Records.")
    +@CapabilityDescription("Parses JSON records and evaluates user-defined JSON Path's against each JSON object. The reader does not require the "
    --- End diff --
    
    I would be hesitant to indicate "The reader does not require the flow file content to be well-formed JSON." This gives me the impression that improper JSON will still be handled correctly, perhaps by skipping over the invalid parts? Perhaps we should word it as "While the reader expects each record to be well-formed JSON, the content of a FlowFile may consist of many records, either as a well-formed JSON array, or a series of JSON records with optional whitespace between them, such as the common 'JSON-per-line' format." or something of that nature.


---

[GitHub] nifi pull request #2640: NIFI-4456: Support multiple JSON objects in JSON re...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/nifi/pull/2640


---