the-other-tim-brown commented on code in PR #9743:
URL: https://github.com/apache/hudi/pull/9743#discussion_r1357634303


##########
hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java:
##########
@@ -1081,6 +1083,69 @@ private static Object 
rewritePrimaryTypeWithDiffSchemaType(Object oldValue, Sche
     throw new AvroRuntimeException(String.format("cannot support rewrite value 
for schema type: %s since the old schema type is: %s", newSchema, oldSchema));
   }
 
+  /**
+   * Avro does not support type promotion from numbers to string. This 
function returns true if
+   * it will be necessary to rewrite the record to support this promotion.
+   * NOTE: this does not determine whether the writerSchema and readerSchema 
are compatible.
+   * It is just trying to find if the reader expects a number to be promoted 
to string, as quick as possible.
+   */
+  public static boolean recordNeedsRewriteForExtendedAvroTypePromotion(Schema 
writerSchema, Schema readerSchema) {
+    if (writerSchema.equals(readerSchema)) {
+      return false;
+    }
+    switch (readerSchema.getType()) {
+      case RECORD:
+        Map<String, Schema.Field> writerFields = new HashMap<>();
+        for (Schema.Field field : writerSchema.getFields()) {
+          writerFields.put(field.name(), field);
+        }
+        for (Schema.Field field : readerSchema.getFields()) {
+          if (writerFields.containsKey(field.name())) {
+            if 
(recordNeedsRewriteForExtendedAvroTypePromotion(writerFields.get(field.name()).schema(),
 field.schema())) {
+              return true;
+            }

Review Comment:
   simply return the result of 
`recordNeedsRewriteForExtendedAvroTypePromotion(writerFields.get(field.name()).schema(),
 field.schema())` here?



-- 
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: commits-unsubscr...@hudi.apache.org

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

Reply via email to