kubaugust commented on code in PR #11817:
URL: https://github.com/apache/nifi/pull/11817#discussion_r4323909750


##########
nifi-commons/nifi-record/src/main/java/org/apache/nifi/serialization/record/util/DataTypeUtils.java:
##########
@@ -1922,17 +1922,33 @@ public static boolean isRecordWider(final RecordSchema 
potentiallyWider, final R
                 continue;
             }
 
-            final Optional<DataType> widerType = 
getWiderType(widerField.get().getDataType(), narrowerField.getDataType());
-            if (widerType.isEmpty()) {
+            if (!isWiderOrEqual(widerField.get().getDataType(), 
narrowerField.getDataType())) {
                 return false;
             }
+        }
 
-            if (!widerType.get().equals(widerField.get().getDataType())) {
-                return false;
+        return true;
+    }
+
+    private static boolean isWiderOrEqual(final DataType potentiallyWider, 
final DataType potentiallyNarrower) {
+        final RecordFieldType widerFieldType = potentiallyWider.getFieldType();
+        final RecordFieldType narrowerFieldType = 
potentiallyNarrower.getFieldType();
+
+        if (widerFieldType == RecordFieldType.RECORD && narrowerFieldType == 
RecordFieldType.RECORD) {
+            final RecordSchema widerSchema = ((RecordDataType) 
potentiallyWider).getChildSchema();
+            final RecordSchema narrowerSchema = ((RecordDataType) 
potentiallyNarrower).getChildSchema();
+            if (widerSchema != null && narrowerSchema != null) {
+                return isRecordWider(widerSchema, narrowerSchema);
+            }
+        } else if (widerFieldType == RecordFieldType.ARRAY && 
narrowerFieldType == RecordFieldType.ARRAY) {
+            final DataType widerElementType = ((ArrayDataType) 
potentiallyWider).getElementType();
+            final DataType narrowerElementType = ((ArrayDataType) 
potentiallyNarrower).getElementType();
+            if (widerElementType != null && narrowerElementType != null) {
+                return isWiderOrEqual(widerElementType, narrowerElementType) 
&& 
RecordFieldType.ARRAY.getArrayDataType(widerElementType).equals(potentiallyWider);

Review Comment:
   Absolutely, rewritten



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