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 2019/01/26 12:37:36 UTC

[GitHub] MikeThomsen commented on a change in pull request #3267: NIFI-5943 support conversions from List to Avro ARRAY and from Map to Avro RECORD

MikeThomsen 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_r251198118
 
 

 ##########
 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:
   I would recommend adding a check for a `RECORD` data type in each field and then doing a recursive call to get a `Map<String, Object`> for that. Otherwise you're going to end up with only a partial conversion which could potentially introduce some ugly issues when trying to convert a complicated record structure into a JSON Map<String, Object> like structure.

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


With regards,
Apache Git Services