linliu-code commented on code in PR #13990:
URL: https://github.com/apache/hudi/pull/13990#discussion_r2386329830


##########
hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java:
##########
@@ -1231,4 +1262,168 @@ void 
recordNeedsRewriteForExtendedAvroTypePromotion(Schema writerSchema, Schema
     boolean result = 
HoodieAvroUtils.recordNeedsRewriteForExtendedAvroTypePromotion(writerSchema, 
readerSchema);
     assertEquals(expected, result);
   }
+
+  /**
+   * Utility class for generating random GenericRecord instances.
+   */
+  private static class AvroTestUtils {
+    private static final Random RANDOM = new Random(42);
+
+    /**
+     * Generate a list of random GenericRecord instances
+     */
+    public static List<GenericRecord> generateRandomRecords(Schema schema, int 
count) {
+      List<GenericRecord> records = new ArrayList<>();
+      for (int i = 0; i < count; i++) {
+        records.add(generateRandomRecord(schema));
+      }
+      return records;
+    }
+
+    /**
+     * Generate a random GenericRecord for the given schema
+     */
+    public static GenericRecord generateRandomRecord(Schema schema) {
+      GenericRecord record = new GenericData.Record(schema);
+      for (Schema.Field field : schema.getFields()) {
+        Object value = generateRandomValue(field.schema(), field.defaultVal());
+        record.put(field.pos(), value);
+      }
+      return record;
+    }
+
+    /**
+     * Generate a random value for the given schema type
+     */
+    private static Object generateRandomValue(Schema schema, Object 
defaultValue) {
+      // CASE 1: Handle default value
+      if (defaultValue != null
+          && !(defaultValue instanceof org.apache.avro.JsonProperties.Null)
+          && RANDOM.nextBoolean()) {
+        return defaultValue;
+      }
+      Schema actualSchema = schema;
+      try {
+        actualSchema = resolveNullableSchema(schema);
+      } catch (Exception e) {
+        // If we can't resolve the schema, just use the original
+        // Op.
+      }
+      // CASE 2: Handle union type
+      if (schema.getType() == Schema.Type.UNION) {
+        List<Schema> types = schema.getTypes();
+        // For nullable unions, sometimes return null
+        if (types.size() == 2 && types.get(0).getType() == Schema.Type.NULL && 
RANDOM.nextBoolean()) {
+          return null;
+        }
+        // Choose a non-null type from the union
+        Schema nonNullType = types.stream()

Review Comment:
   right. removed.



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