NIFI-8320: Fix column mismatch in PutDatabaseRecord#5024
NIFI-8320: Fix column mismatch in PutDatabaseRecord#5024mattyb149 wants to merge 4 commits intoapache:mainfrom
Conversation
...standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
Outdated
Show resolved
Hide resolved
gresockj
left a comment
There was a problem hiding this comment.
Looks good overall, just a couple minor suggestions.
| final ColumnDescription column = columns.get(currentFieldIndex); | ||
| int sqlType = column.dataType; | ||
| final String fieldName = currentRecord.getSchema().getField(currentFieldIndex).getFieldName(); | ||
| String columnName = normalizeColumnName(currentRecord.getSchema().getField(currentFieldIndex).getFieldName(), settings.translateFieldNames); |
There was a problem hiding this comment.
Very minor, but can you reuse fieldName here? Also, I see currentRecord.getSchema() called a couple times, could that be pulled into a local variable around line 693?
There was a problem hiding this comment.
Yeah my bad that's sloppy, I'll change it to reuse local variables for schema, field name, and columns
There was a problem hiding this comment.
call normalizeColumnName method too many times, maybe store the columnName in a list is better.
...standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
Show resolved
Hide resolved
...-processors/src/test/groovy/org/apache/nifi/processors/standard/TestPutDatabaseRecord.groovy
Show resolved
Hide resolved
...-processors/src/test/groovy/org/apache/nifi/processors/standard/TestPutDatabaseRecord.groovy
Show resolved
Hide resolved
|
@mattyb149 Can you please also include a testcase of incorrect column ordering while providing values. I ended up creating a duplicate PR #5043. However, an important testcase can be included from there. Thanks. |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for resolving the issue and adding the unit tests for verification @mattyb149! +1 Merging.
|
Thanks to @gresockj, @naddym, @gardellajuanpablo, @greyp9, and @ldd200888 for the comments and contributions, very helpful! |
This closes apache#5024 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This closes apache#5024 Signed-off-by: David Handermann <exceptionfactory@apache.org>
Thank you for submitting a contribution to Apache NiFi.
Please provide a short description of the PR here:
Description of PR
There are two index mappings in PutDatabaseRecord, one for included record fields and a missing one for table columns. The code erroneously used the record field index which may not map to the same column index in the table. This change does a name lookup to get the column corresponding to the record at the field index, and uses that to determine data type.
In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:
For all changes:
Is there a JIRA ticket associated with this PR? Is it referenced
in the commit message?
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.
Has your PR been rebased against the latest commit within the target branch (typically
main)?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
squashor use--forcewhen pushing to allow for clean monitoring of changes.For code changes:
mvn -Pcontrib-check clean installat the rootnififolder?LICENSEfile, including the mainLICENSEfile undernifi-assembly?NOTICEfile, including the mainNOTICEfile found undernifi-assembly?.displayNamein addition to .name (programmatic access) for each of the new properties?For documentation related changes:
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.