This is an automated email from the ASF dual-hosted git repository.
sivabalan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 82a199373298 fix: add handling for null schema edge case (#14020)
82a199373298 is described below
commit 82a1993732982220b3505cc20bb1311fa7e4714f
Author: Tim Brown <[email protected]>
AuthorDate: Wed Oct 1 00:49:59 2025 -0400
fix: add handling for null schema edge case (#14020)
---
.../java/org/apache/hudi/avro/HoodieAvroUtils.java | 3 +++
.../java/org/apache/hudi/avro/TestHoodieAvroUtils.java | 18 ++++++++++++++----
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git
a/hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java
b/hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java
index 61792e15f7b9..2dd40387c1d0 100644
--- a/hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java
@@ -282,6 +282,9 @@ public class HoodieAvroUtils {
* @param withOperationField Whether to include the '_hoodie_operation' field
*/
public static Schema addMetadataFields(Schema schema, boolean
withOperationField) {
+ if (isSchemaNull(schema)) {
+ return schema;
+ }
int newFieldsSize = HoodieRecord.HOODIE_META_COLUMNS.size() +
(withOperationField ? 1 : 0);
List<Schema.Field> parentFields = new
ArrayList<>(schema.getFields().size() + newFieldsSize);
diff --git
a/hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java
b/hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java
index 2371c5b2caed..b655f9bfdc8e 100644
--- a/hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java
+++ b/hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java
@@ -91,8 +91,6 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -134,8 +132,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
*/
public class TestHoodieAvroUtils {
- private static final Logger LOG =
LoggerFactory.getLogger(TestHoodieAvroUtils.class);
-
private static final String EVOLVED_SCHEMA = "{\"type\":
\"record\",\"name\": \"testrec1\",\"fields\": [ "
+ "{\"name\": \"timestamp\",\"type\": \"double\"},{\"name\":
\"_row_key\", \"type\": \"string\"},"
+ "{\"name\": \"non_pii_col\", \"type\": \"string\"},"
@@ -269,6 +265,20 @@ public class TestHoodieAvroUtils {
public static Schema SCHEMA_WITH_NESTED_FIELD_LARGE = new
Schema.Parser().parse(SCHEMA_WITH_NESTED_FIELD_LARGE_STR);
+ @Test
+ void testAddMetaFields() {
+ // validate null schema does not throw errors
+ assertNull(HoodieAvroUtils.addMetadataFields(null));
+ Schema nullSchema = Schema.create(Schema.Type.NULL);
+ assertEquals(nullSchema, HoodieAvroUtils.addMetadataFields(nullSchema));
+ // test with non-null schema
+ Schema schema = HoodieAvroUtils.addMetadataFields(new
Schema.Parser().parse(EXAMPLE_SCHEMA));
+ assertEquals(NUM_FIELDS_IN_EXAMPLE_SCHEMA +
HoodieRecord.HOODIE_META_COLUMNS.size(), schema.getFields().size());
+ for (String metaCol : HoodieRecord.HOODIE_META_COLUMNS) {
+ assertNotNull(schema.getField(metaCol));
+ }
+ }
+
@Test
public void testPropsPresent() {
Schema schema = HoodieAvroUtils.addMetadataFields(new
Schema.Parser().parse(EXAMPLE_SCHEMA));