markap14 commented on a change in pull request #3724: NIFI-6640 - UNION/CHOICE
types not handled correctly
URL: https://github.com/apache/nifi/pull/3724#discussion_r324306962
##########
File path:
nifi-nar-bundles/nifi-extension-utils/nifi-record-utils/nifi-avro-record-utils/src/main/java/org/apache/nifi/avro/AvroTypeUtil.java
##########
@@ -877,6 +878,18 @@ private static Object convertToAvroObject(final Object
rawValue, final Schema fi
*/
private static Object convertUnionFieldValue(final Object originalValue,
final Schema fieldSchema, final Function<Schema, Object> conversion, final
String fieldName) {
boolean foundNonNull = false;
+
+ Optional<Schema> mostSuitableType = DataTypeUtils.findMostSuitableType(
+ originalValue,
+ fieldSchema.getTypes().stream().filter(schema ->
schema.getType() != Type.NULL).collect(Collectors.toList()),
+ subSchema -> AvroTypeUtil.determineDataType(subSchema)
+ );
+ if (mostSuitableType.isPresent()) {
+ Object convertedVAlue = conversion.apply(mostSuitableType.get());
Review comment:
This would be made simpler by simply returning `conversion.apply(...)`
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services