ChrisSamo632 commented on code in PR #7745:
URL: https://github.com/apache/nifi/pull/7745#discussion_r1420401479


##########
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java:
##########
@@ -469,21 +473,51 @@ public static RecordSchema inferSchema(final Map<String, 
Object> values, final S
             final RecordField recordField = new RecordField(key, 
inferredDataType, true);
             inferredFieldTypes.add(recordField);
 
-            final Object coercedValue = convertType(rawValue, 
inferredDataType, fieldName, charset);
-            coercedValues.put(key, coercedValue);
+            convertType(rawValue, inferredDataType, fieldName, charset);
         }
 
-        final RecordSchema inferredSchema = new 
SimpleRecordSchema(inferredFieldTypes);
-        return inferredSchema;
+        return new SimpleRecordSchema(inferredFieldTypes);
     }
 
     public static Record toRecord(final Object value, final String fieldName, 
final Charset charset) {
+        return toRecord(value, fieldName, charset, false);
+    }
+
+    private static Object covertObjectToRecord(final Object rawValue, final 
String key, final Charset charset) {
+        final Object coercedValue;
+        if (rawValue instanceof Map<?, ?>) {
+            coercedValue = toRecord(rawValue, key, charset, true);
+        } else if (rawValue instanceof Object[]) {
+            final Object[] objArray = (Object[]) rawValue;
+            coercedValue = Arrays.stream(objArray).noneMatch(o -> o instanceof 
Map<?, ?>)
+                    ? objArray
+                    : Arrays.stream(objArray).map(o -> toRecord(o, key, 
charset, true)).toArray();
+        } else if (rawValue instanceof Collection<?>) {
+            final Collection<?> objCollection = (Collection<?>) rawValue;
+            // Records have ARRAY DataTypes, so convert any Collections
+            coercedValue = objCollection.stream().noneMatch(o -> o instanceof 
Map<?, ?>)
+                    ? objCollection.toArray()
+                    : objCollection.stream().map(o -> toRecord(o, key, 
charset, true)).toArray();

Review Comment:
   That's fair, I've reverted this and found a couple of other Streams within 
`DataTypeUtils` that should probably be changed too, will include in this PR



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to