gresockj commented on a change in pull request #5024:
URL: https://github.com/apache/nifi/pull/5024#discussion_r621454674



##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -691,15 +691,27 @@ private void executeDML(final ProcessContext context, 
final ProcessSession sessi
 
                     final Object[] values = currentRecord.getValues();
                     final List<DataType> dataTypes = 
currentRecord.getSchema().getDataTypes();
-                    List<ColumnDescription> columns = 
tableSchema.getColumnsAsList();
 
                     for (int i = 0; i < fieldIndexes.size(); i++) {
                         final int currentFieldIndex = fieldIndexes.get(i);
                         Object currentValue = values[currentFieldIndex];
                         final DataType dataType = 
dataTypes.get(currentFieldIndex);
                         final int fieldSqlType = 
DataTypeUtils.getSQLTypeValue(dataType);
-                        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);

Review 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?

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/PutDatabaseRecord.java
##########
@@ -691,15 +691,27 @@ private void executeDML(final ProcessContext context, 
final ProcessSession sessi
 
                     final Object[] values = currentRecord.getValues();
                     final List<DataType> dataTypes = 
currentRecord.getSchema().getDataTypes();
-                    List<ColumnDescription> columns = 
tableSchema.getColumnsAsList();
 
                     for (int i = 0; i < fieldIndexes.size(); i++) {
                         final int currentFieldIndex = fieldIndexes.get(i);
                         Object currentValue = values[currentFieldIndex];
                         final DataType dataType = 
dataTypes.get(currentFieldIndex);
                         final int fieldSqlType = 
DataTypeUtils.getSQLTypeValue(dataType);
-                        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);
+                        int sqlType;
+                        final ColumnDescription column = 
tableSchema.getColumns().get(columnName);
+                        // 'column' should not be null here as the 
fieldIndexes should correspond to fields that match table columns, but better 
to handle just in case
+                        if (column == null) {
+                            if (!settings.ignoreUnmappedFields) {
+                                throw new SQLDataException("Cannot map field 
'" + fieldName + "' to any column in the database\n"

Review comment:
       Perhaps String.format()

##########
File path: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/groovy/org/apache/nifi/processors/standard/TestPutDatabaseRecord.groovy
##########
@@ -301,6 +301,73 @@ class TestPutDatabaseRecord {
         conn.close()
     }
 
+    @Test
+    void testInsertNonRequiredColumns() throws InitializationException, 
ProcessException, SQLException, IOException {

Review comment:
       Do you want to add a test case to show SQLDataException being thrown?




-- 
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:
us...@infra.apache.org


Reply via email to