You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2021/02/17 21:49:15 UTC

[GitHub] [nifi] ChrisSamo632 opened a new pull request #4828: NIFI-8232 CSV Parsers optionally allow/reject duplicate header names

ChrisSamo632 opened a new pull request #4828:
URL: https://github.com/apache/nifi/pull/4828


   Thank you for submitting a contribution to Apache NiFi.
   
   Please provide a short description of the PR here:
   
   #### Description of PR
   
   CSVReader provides option to allow/reject duplicate header names in CSV files.
   
   Re-instates the ability for the Apache Commons CSV Parser to reject such CSV files (the library functionality changes between version 1.6 and 1.8, but NiFi didn't account for that when upgrading the dependency).
   
   Adds the ability for the Jackson CSV Parser to also detect and reject duplicate header names (although that doesn't appear to be a JAckson-native capability).
   
   
   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 `main`)?
   
   - [x] Is your initial contribution a single, squashed commit? _Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not `squash` or use `--force` when pushing to allow for clean monitoring of changes._
   
   ### 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?
   - [ ] Have you verified that the full build is successful on JDK 8?
   - [x] Have you verified that the full build is successful on JDK 11?
   - ~[ ] 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:
   - ~[ ] 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 GitHub Actions CI for build issues and submit an update to your PR as soon as possible.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on pull request #4828: NIFI-8232 CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#issuecomment-783499390


   Maybe the PR / jira should have REGRESSION in them, just so it is clear that this is fixing a regression?
   I'm not sure there wouldn't need to be ( or that it wouldn't be good to have ) something in the migration guide that tells the story. 
   But a committer may have a better take on that.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] asfgit closed pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #4828:
URL: https://github.com/apache/nifi/pull/4828


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ChrisSamo632 commented on a change in pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ChrisSamo632 commented on a change in pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#discussion_r580565064



##########
File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestCSVHeaderSchemaStrategy.java
##########
@@ -66,9 +66,37 @@ public void testSimple() throws SchemaNotFoundException, IOException {
             .allMatch(field -> field.getDataType().equals(RecordFieldType.STRING.getDataType())));
     }
 

Review comment:
       The "Use String Fields From Header" Schema Access Strategy is parser-agnostic (as far as I can tell) in the CSVReader service, however the implementation is hard-coded to use the Apache Commons CSV Parser (I've not changed that).
   
   That parser sets up its own CSV Format using the same (updated) CSVUtils methods, so it should take into account the settings changes.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ChrisSamo632 commented on pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ChrisSamo632 commented on pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#issuecomment-783661047


   > Maybe the PR / jira should have REGRESSION in them, just so it is clear that this is fixing a regression?
   > I'm not sure there wouldn't need to be ( or that it wouldn't be good to have ) something in the migration guide that tells the story.
   > But a committer may have a better take on that.
   
   Updated the PR and Jira ticket titles (assume that's what you meant, otherwise do you have an example of what you mean)?
   
   Don't think I have access to update the migration guide, so will leave that for a committer to comment (as you suggest).


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ChrisSamo632 commented on a change in pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ChrisSamo632 commented on a change in pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#discussion_r580569318



##########
File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/JacksonCSVRecordReader.java
##########
@@ -108,6 +112,17 @@ public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFie
                     rawFieldNames = schema.getFieldNames();
                 } else {
                     rawFieldNames = Arrays.asList(csvRecord);
+                    if (rawFieldNames.size() > schema.getFieldCount() && !allowDuplicateHeaderNames) {
+                        final Set<String> deDupe = new HashSet<>(schema.getFieldCount());

Review comment:
       Yes. But that's because I've replicated the same functionality as Apache Commons CSV, which reports a single error (somewhat annoyingly).
   
   We could indeed have a separate approach for Jackson (which I actually coded first), but I decided to keep the experience as close as possible irrespective of chosen Parser.
   
   Happy to discuss/be overruled on that.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on pull request #4828: NIFI-8232 CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#issuecomment-783379624


   So, the default with the change matches the behavior of 1.13 before the change?  or goes back to some non-regressed version?  Can you clarify?


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ChrisSamo632 commented on a change in pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ChrisSamo632 commented on a change in pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#discussion_r580574752



##########
File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestCSVRecordReader.java
##########
@@ -592,6 +585,47 @@ public void testExtraFieldNotInHeader() throws IOException, MalformedRecordExcep
         }
     }
 

Review comment:
       Agreed, added.
   
   Header Names are case-sensitive, so they're treated as different columns/fields.
   
   Handling of duplicates is different between Apache and Jackson, which the updated tests will show (and I'll add something to the "Allow Duplicate Headers" property description)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on a change in pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#discussion_r580649669



##########
File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/JacksonCSVRecordReader.java
##########
@@ -108,6 +112,17 @@ public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFie
                     rawFieldNames = schema.getFieldNames();
                 } else {
                     rawFieldNames = Arrays.asList(csvRecord);
+                    if (rawFieldNames.size() > schema.getFieldCount() && !allowDuplicateHeaderNames) {
+                        final Set<String> deDupe = new HashSet<>(schema.getFieldCount());

Review comment:
       That is fair enough
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ChrisSamo632 commented on a change in pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ChrisSamo632 commented on a change in pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#discussion_r580586615



##########
File path: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-standard-record-utils/src/main/java/org/apache/nifi/csv/CSVUtils.java
##########
@@ -136,6 +136,15 @@
         .defaultValue("UTF-8")
         .required(true)
         .build();
+    public static final PropertyDescriptor ALLOW_DUPLICATE_HEADER_NAMES = new PropertyDescriptor.Builder()
+        .name("csvutils-allow-duplicate-header-names")
+        .displayName("Allow Duplicate Header Names")

Review comment:
       Explanations added.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#issuecomment-783735252


   +1 looks good to me, nice catch and contribution @ChrisSamo632 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] pvillard31 commented on pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
pvillard31 commented on pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#issuecomment-783928054


   Merged to main, thanks @ChrisSamo632 !


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on a change in pull request #4828: NIFI-8232 CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#discussion_r580400233



##########
File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestCSVHeaderSchemaStrategy.java
##########
@@ -66,9 +66,37 @@ public void testSimple() throws SchemaNotFoundException, IOException {
             .allMatch(field -> field.getDataType().equals(RecordFieldType.STRING.getDataType())));
     }
 

Review comment:
       which is this testing, Jackson or Apache?  

##########
File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestCSVRecordReader.java
##########
@@ -592,6 +585,47 @@ public void testExtraFieldNotInHeader() throws IOException, MalformedRecordExcep
         }
     }
 

Review comment:
       You may want to test with multiple duplicates,  id, name, country, id, name, country.
   Also, I assume case doesn't matter, but that is an assumption.
   id, name, country, ID, NAME, COUNTRY

##########
File path: nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-standard-record-utils/src/main/java/org/apache/nifi/csv/CSVUtils.java
##########
@@ -136,6 +136,15 @@
         .defaultValue("UTF-8")
         .required(true)
         .build();
+    public static final PropertyDescriptor ALLOW_DUPLICATE_HEADER_NAMES = new PropertyDescriptor.Builder()
+        .name("csvutils-allow-duplicate-header-names")
+        .displayName("Allow Duplicate Header Names")

Review comment:
       Maybe this should say what happens if there *are* duplicate headers found too

##########
File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/csv/JacksonCSVRecordReader.java
##########
@@ -108,6 +112,17 @@ public Record nextRecord(final boolean coerceTypes, final boolean dropUnknownFie
                     rawFieldNames = schema.getFieldNames();
                 } else {
                     rawFieldNames = Arrays.asList(csvRecord);
+                    if (rawFieldNames.size() > schema.getFieldCount() && !allowDuplicateHeaderNames) {
+                        final Set<String> deDupe = new HashSet<>(schema.getFieldCount());

Review comment:
       So, if I have multiple duplicate names, then I'm going to have to iterate through these errors, one by one, field by field.
   Have you given thought to tracking the duplicates, and then throwing if there are any, and include all the duplicate fields in that exception?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ChrisSamo632 commented on pull request #4828: NIFI-8232 CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ChrisSamo632 commented on pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#issuecomment-783425425


   > So, the default with the change matches the behavior of 1.13 before the change? or goes back to some non-regressed version? Can you clarify?
   
   The default (for the Apache Commons CSV parser) goes back to the funcitonality provided before the upgrade to commons-csv:1.8 (which was at some point between 1.11.4 and 1.13.0 - I stumbled into this functionality change when looking to upgrade between these NiFi versions).
   
   I added the ability for the Jackson CSV parser to have the same (or at least functionally similar) behaviour, which it didn't have before.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] ottobackwards commented on a change in pull request #4828: NIFI-8232 REGRESSION CSV Parsers optionally allow/reject duplicate header names

Posted by GitBox <gi...@apache.org>.
ottobackwards commented on a change in pull request #4828:
URL: https://github.com/apache/nifi/pull/4828#discussion_r580650094



##########
File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/test/java/org/apache/nifi/csv/TestCSVHeaderSchemaStrategy.java
##########
@@ -66,9 +66,37 @@ public void testSimple() throws SchemaNotFoundException, IOException {
             .allMatch(field -> field.getDataType().equals(RecordFieldType.STRING.getDataType())));
     }
 

Review comment:
       Is there someplace where are are parser specific tests?  It seems we would want  to explicitly test each




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org