SavtechSolutions commented on a change in pull request #3267: NIFI-5943 support 
conversions from List to Avro ARRAY and from Map to Avro RECORD
URL: https://github.com/apache/nifi/pull/3267#discussion_r253530573
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/avro/AvroTypeUtil.java
 ##########
 @@ -672,10 +673,20 @@ private static Object convertToAvroObject(final Object 
rawValue, final Schema fi
             case RECORD:
                 final GenericData.Record avroRecord = new 
GenericData.Record(fieldSchema);
 
-                final Record record = (Record) rawValue;
-                for (final RecordField recordField : 
record.getSchema().getFields()) {
-                    final Object recordFieldValue = 
record.getValue(recordField);
-                    final String recordFieldName = recordField.getFieldName();
+                final Set<Map.Entry<String, Object>> entries;
+                if (rawValue instanceof Map) {
+                    final Map<String, Object> map = (Map<String, Object>) 
rawValue;
+                    entries = map.entrySet();
+                } else if (rawValue instanceof Record) {
+                    entries = new HashSet<>();
+                    final Record record = (Record) rawValue;
+                    record.getSchema().getFields().forEach(field -> 
entries.add(new AbstractMap.SimpleEntry<>(field.getFieldName(), 
record.getValue(field))));
 
 Review comment:
   The recursive conversion is already being taken care of later on, at line 
696: `final Object converted = convertToAvroObject(recordFieldValue, 
field.schema(), fieldName + "/" + recordFieldName, charset);`, where each 
field's value (pulled via `record.getValue(field)` earlier for a RECORD, or 
directly pulled out from the MAP) is passed recursively to 
`convertToAvroObject`, and the result of that is put into the Avro record.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to