You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "dan-s1 (via GitHub)" <gi...@apache.org> on 2025/05/28 15:31:13 UTC

[PR] NIFI-14596 Added logic to the ExcelHeaderSchemaStrategy to rename duplicate column names thereby ensuring no data loss or skewing of data. [nifi]

dan-s1 opened a new pull request, #9975:
URL: https://github.com/apache/nifi/pull/9975

   <!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
   <!-- contributor license agreements.  See the NOTICE file distributed with -->
   <!-- this work for additional information regarding copyright ownership. -->
   <!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
   <!-- (the "License"); you may not use this file except in compliance with -->
   <!-- the License.  You may obtain a copy of the License at -->
   <!--     http://www.apache.org/licenses/LICENSE-2.0 -->
   <!-- Unless required by applicable law or agreed to in writing, software -->
   <!-- distributed under the License is distributed on an "AS IS" BASIS, -->
   <!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
   <!-- See the License for the specific language governing permissions and -->
   <!-- limitations under the License. -->
   
   # Summary
   
   [NIFI-14596](https://issues.apache.org/jira/browse/NIFI-14596)
   
   # Tracking
   
   Please complete the following tracking steps prior to pull request creation.
   
   ### Issue Tracking
   
   - [ ] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
   
   ### Pull Request Tracking
   
   - [ ] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
   - [ ] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
   
   ### Pull Request Formatting
   
   - [ ] Pull Request based on current revision of the `main` branch
   - [ ] Pull Request refers to a feature branch with one commit containing changes
   
   # Verification
   
   Please indicate the verification steps performed prior to pull request creation.
   
   ### Build
   
   - [ ] Build completed using `mvn clean install -P contrib-check`
     - [ ] JDK 21
   
   ### Licensing
   
   - [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
   - [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
   
   ### Documentation
   
   - [ ] Documentation formatting appears as expected in rendered files
   


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

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


Re: [PR] NIFI-14596 Added logic to the ExcelHeaderSchemaStrategy to rename duplicate column names thereby ensuring no data loss or skewing of data. [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory merged PR #9975:
URL: https://github.com/apache/nifi/pull/9975


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

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


Re: [PR] NIFI-14596 Added logic to the ExcelHeaderSchemaStrategy to rename duplicate column names thereby ensuring no data loss or skewing of data. [nifi]

Posted by "dan-s1 (via GitHub)" <gi...@apache.org>.
dan-s1 commented on PR #9975:
URL: https://github.com/apache/nifi/pull/9975#issuecomment-2945811166

   @exceptionfactory When you have a chance, can you please take a look at this PR? I believe it corrects the bug I had reported and utilizes your suggestion of using a one up number to rename a column. Thanks!


-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

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


Re: [PR] NIFI-14596 Added logic to the ExcelHeaderSchemaStrategy to rename duplicate column names thereby ensuring no data loss or skewing of data. [nifi]

Posted by "exceptionfactory (via GitHub)" <gi...@apache.org>.
exceptionfactory commented on code in PR #9975:
URL: https://github.com/apache/nifi/pull/9975#discussion_r2132505128


##########
nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/java/org/apache/nifi/excel/ExcelHeaderSchemaStrategy.java:
##########
@@ -126,8 +130,26 @@ private List<String> getFieldNames(int firstRowIndex, Row row) throws SchemaNotF
                 fieldNames.add(fieldName);
             }
         }
+        final List<String> renamedDuplicateFieldNames = renameDuplicateFieldNames(fieldNames);
 
-        return fieldNames;
+        return renamedDuplicateFieldNames;
+    }
+
+    private List<String> renameDuplicateFieldNames(List<String> fieldNames) {
+        final Map<String, Integer> fieldNameCounts = new HashMap<>();
+        final List<String> renamedDuplicateFieldNames = new ArrayList<>();
+
+        for (String fieldName : fieldNames) {
+            if (fieldNameCounts.containsKey(fieldName)) {
+                int count = fieldNameCounts.get(fieldName) + 1;
+                fieldNameCounts.put(fieldName, count);
+                renamedDuplicateFieldNames.add(fieldName + "_" + count);

Review Comment:
   ```suggestion
                   final int count = fieldNameCounts.get(fieldName);
                   renamedDuplicateFieldNames.add("%s_%d".formatted(fieldName, count));
                   fieldNameCounts.put(fieldName, count + 1);
   ```



##########
nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/java/org/apache/nifi/excel/ExcelHeaderSchemaStrategy.java:
##########
@@ -126,8 +130,26 @@ private List<String> getFieldNames(int firstRowIndex, Row row) throws SchemaNotF
                 fieldNames.add(fieldName);
             }
         }
+        final List<String> renamedDuplicateFieldNames = renameDuplicateFieldNames(fieldNames);
 
-        return fieldNames;
+        return renamedDuplicateFieldNames;
+    }
+
+    private List<String> renameDuplicateFieldNames(List<String> fieldNames) {

Review Comment:
   ```suggestion
       private List<String> renameDuplicateFieldNames(final List<String> fieldNames) {
   ```



##########
nifi-extension-bundles/nifi-poi-bundle/nifi-poi-services/src/main/java/org/apache/nifi/excel/ExcelHeaderSchemaStrategy.java:
##########
@@ -47,8 +48,11 @@ public class ExcelHeaderSchemaStrategy implements SchemaAccessStrategy {
     static final int NUM_ROWS_TO_DETERMINE_TYPES = 10; // NOTE: This number is arbitrary.
     static final AllowableValue USE_STARTING_ROW = new AllowableValue("Use Starting Row", "Use Starting Row",
             "The configured first row of the Excel file is a header line that contains the names of the columns. The schema will be derived by using the "
-                    + "column names in the header of the first sheet and the following " + NUM_ROWS_TO_DETERMINE_TYPES + " rows to determine the type(s) of each column " +
-                      "while the configured header rows of subsequent sheets are skipped.");
+                    + "column names in the header of the first sheet and the following " + NUM_ROWS_TO_DETERMINE_TYPES + " rows to determine the type(s) of each column "
+                    + "while the configured header rows of subsequent sheets are skipped. "
+                    + "NOTE: If there are duplicate column names then each subsequent duplicate column name is given a one up number. "
+                    + "For example, column names \"Frequency\", \"Intervals\", \"Frequency\" \"Name\", \"Frequency\", \"Intervals\" will be "
+                    + "changed to \"Frequency\", \"Intervals\", \"Frequency_2\" \"Name\", \"Frequency_3\", \"Intervals_2\".");

Review Comment:
   Recommend simplifying the example to focus on a single column for clarity:
   ```suggestion
                       + "For example, column names \"Name\", \"Name\" will be "
                       + "changed to \"Name\", \"Name_1\"");
   ```



-- 
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.

To unsubscribe, e-mail: issues-unsubscribe@nifi.apache.org

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