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_r324311037
 
 

 ##########
 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()
+                .map(DataType::getFieldType)
+                .filter(possibleDataType -> 
!possibleDataType.equals(RecordFieldType.STRING))
+                .filter(possibleDataType -> 
possibleDataType.isWiderThan(additionalFieldType))
+                .findAny()
+                .isPresent();
+
+        if (!hasWiderNonString) {
+            java.util.Iterator<DataType> possibleDataTypeIterator = 
possibleDataTypes.iterator();
 
 Review comment:
   Should import `java.util.Iterator` rather than declaring the full package 
inline.

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

Reply via email to