dan-s1 commented on code in PR #8331:
URL: https://github.com/apache/nifi/pull/8331#discussion_r1473274933


##########
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java:
##########
@@ -1792,37 +1796,77 @@ public static Optional<DataType> getWiderType(final 
DataType thisDataType, final
                     return Optional.of(thisDataType);
                 }
                 break;
+            case RECORD:
+                if (otherFieldType != RecordFieldType.RECORD)  {
+                    return Optional.empty();
+                }
+
+                final RecordDataType thisRecordDataType = (RecordDataType) 
thisDataType;
+                final RecordDataType otherRecordDataType = (RecordDataType) 
otherDataType;
+                return getWiderRecordType(thisRecordDataType, 
otherRecordDataType);
         }
 
         return Optional.empty();
     }
 
-    private static boolean isDecimalType(final RecordFieldType fieldType) {
-        switch (fieldType) {
-            case FLOAT:
-            case DOUBLE:
-            case DECIMAL:
-                return true;
-            default:
-                return false;
+    private static Optional<DataType> getWiderRecordType(final RecordDataType 
thisRecordDataType, final RecordDataType otherRecordDataType) {
+        final RecordSchema thisSchema = thisRecordDataType.getChildSchema();
+        final RecordSchema otherSchema = otherRecordDataType.getChildSchema();
+
+        if (thisSchema == null && otherSchema != null) {
+            return Optional.of(otherRecordDataType);
+        } else if (thisSchema != null && otherSchema == null) {
+            return Optional.of(thisRecordDataType);
+        } else if (thisSchema == null && otherSchema == null) {
+            return Optional.empty();
+        }
+
+        final Set<RecordField> thisFields = new 
HashSet<>(thisSchema.getFields());
+        final Set<RecordField> otherFields = new 
HashSet<>(otherSchema.getFields());
+
+        boolean allFieldsPresent = true;
+        for (final RecordField otherField : otherFields) {
+            if (!thisFields.contains(otherField)) {
+                allFieldsPresent = false;
+                break;
+            }
         }
+
+        if (allFieldsPresent) {
+            return Optional.of(thisRecordDataType);
+        }
+
+        allFieldsPresent = true;
+        for (final RecordField thisField : thisFields) {
+            if (!otherFields.contains(thisField)) {
+                allFieldsPresent = false;
+                break;
+            }
+        }
+
+        if (allFieldsPresent) {
+            return Optional.of(otherRecordDataType);
+        }

Review Comment:
   Couldn't this be simplified with 
   ```suggestion
           if (thisFields.containsAll(otherFields)) {
               return Optional.of(thisRecordDataType);
           }
   
           if (otherFields.containsAll(thisFields)) {
               return Optional.of(otherRecordDataType);
           }
   ```



-- 
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: issues-unsubscr...@nifi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to