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_r324310345
########## File path: nifi-nar-bundles/nifi-standard-services/nifi-record-serialization-services-bundle/nifi-record-serialization-services/src/main/java/org/apache/nifi/schema/inference/FieldTypeInference.java ########## @@ -62,36 +62,44 @@ public void addPossibleDataType(final DataType dataType) { final RecordSchema newSchema = ((RecordDataType) dataType).getChildSchema(); final RecordSchema mergedSchema = DataTypeUtils.merge(singleDataTypeSchema, newSchema); + possibleDataTypes.remove(singleDataType); singleDataType = RecordFieldType.RECORD.getRecordDataType(mergedSchema); + possibleDataTypes.add(singleDataType); return; } - if (singleFieldType.isWiderThan(additionalFieldType)) { - // Assigned type is already wide enough to encompass the given type - return; + if (possibleDataTypes.isEmpty()) { + possibleDataTypes.add(singleDataType); } - if (additionalFieldType.isWiderThan(singleFieldType)) { - // The given type is wide enough to encompass the assigned type. So changed the assigned type to the given type. - singleDataType = dataType; - return; - } + boolean hasWiderNonString = possibleDataTypes.stream() Review comment: This method is also evaluated against potentially every field in any record whose schema is being inferred, so performance is important. As such, we should avoid use of `Stream`s and instead prefer imperative style programming. ---------------------------------------------------------------- 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 With regards, Apache Git Services