voonhous commented on code in PR #17952:
URL: https://github.com/apache/hudi/pull/17952#discussion_r2741275867


##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchema.java:
##########
@@ -546,10 +559,10 @@ public List<HoodieSchemaField> getFields() {
     if (type != HoodieSchemaType.RECORD) {
       throw new IllegalStateException("Cannot get fields from non-record 
schema: " + type);
     }
-
-    return avroSchema.getFields().stream()
-        .map(HoodieSchemaField::new)
-        .collect(Collectors.toList());
+    if (fields == null) {
+      fields = 
avroSchema.getFields().stream().map(HoodieSchemaField::new).collect(Collectors.toList());

Review Comment:
   Should we use `Collections.unmodifiableList()` here to ensure the cached 
fields list remains immutable?



##########
hudi-common/src/main/java/org/apache/hudi/common/schema/HoodieSchemaField.java:
##########
@@ -116,7 +116,7 @@ public static HoodieSchemaField of(String name, 
HoodieSchema schema, String doc,
     Schema avroSchema = schema.getAvroSchema();
     ValidationUtils.checkState(avroSchema != null, "Schema's Avro schema 
cannot be null");
     Schema.Field avroField;
-    if (defaultVal == HoodieSchema.NULL_VALUE && 
schema.getTypes().get(0).getType() != HoodieSchemaType.NULL) {
+    if (defaultVal == HoodieSchema.NULL_VALUE && schema.getType() == 
HoodieSchemaType.UNION && schema.getTypes().get(0).getType() != 
HoodieSchemaType.NULL) {

Review Comment:
   Is there a unit test in `TestHoodieSchemaField` (or `TestHoodieSchema`) to 
explicitly exercise the lines changed here? Although behaviour didn't change, 
do we need to guard against, if not, a test might be good to prevent regression.
   
   A HoodieSchema of type UNION where the first type is not NULL, but the 
default value is NULL.



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