This is an automated email from the ASF dual-hosted git repository.
yihua 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 b3f9cae1e137 fix: Handle empty byte array translation from Payload to
SerializableIndexedRecord (#14038)
b3f9cae1e137 is described below
commit b3f9cae1e1373c15bcc59fd0104bab8f58462f51
Author: Tim Brown <[email protected]>
AuthorDate: Fri Oct 3 12:17:57 2025 -0500
fix: Handle empty byte array translation from Payload to
SerializableIndexedRecord (#14038)
---
.../hudi/common/model/SerializableIndexedRecord.java | 5 ++++-
.../hudi/common/model/TestSerializableIndexRecord.java | 14 ++++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
diff --git
a/hudi-common/src/main/java/org/apache/hudi/common/model/SerializableIndexedRecord.java
b/hudi-common/src/main/java/org/apache/hudi/common/model/SerializableIndexedRecord.java
index 3779e54cecad..336a8effd939 100644
---
a/hudi-common/src/main/java/org/apache/hudi/common/model/SerializableIndexedRecord.java
+++
b/hudi-common/src/main/java/org/apache/hudi/common/model/SerializableIndexedRecord.java
@@ -68,6 +68,9 @@ public class SerializableIndexedRecord implements
GenericRecord, KryoSerializabl
}
public static SerializableIndexedRecord fromAvroBytes(Schema schema, byte[]
bytes) {
+ if (bytes.length == 0) {
+ return null;
+ }
return new SerializableIndexedRecord(schema, bytes);
}
@@ -83,7 +86,7 @@ public class SerializableIndexedRecord implements
GenericRecord, KryoSerializabl
@Override
public Schema getSchema() {
- return schema != null ? schema : getData().getSchema();
+ return schema != null ? schema : record.getSchema();
}
byte[] encodeRecord() {
diff --git
a/hudi-common/src/test/java/org/apache/hudi/common/model/TestSerializableIndexRecord.java
b/hudi-common/src/test/java/org/apache/hudi/common/model/TestSerializableIndexRecord.java
index 0a91cf87a99f..39c012684c6e 100644
---
a/hudi-common/src/test/java/org/apache/hudi/common/model/TestSerializableIndexRecord.java
+++
b/hudi-common/src/test/java/org/apache/hudi/common/model/TestSerializableIndexRecord.java
@@ -33,6 +33,7 @@ import java.io.IOException;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
class TestSerializableIndexRecord {
@@ -90,4 +91,17 @@ class TestSerializableIndexRecord {
deserialized.decodeRecord(schema);
assertSame(parsedRecord, deserialized.getRecord());
}
+
+ @Test
+ void testFromAvroBytes() {
+ GenericRecord originalRecord = new GenericRecordBuilder(schema)
+ .set("field_1", "value1")
+ .set("field_2", 42)
+ .build();
+ byte[] encoded = HoodieAvroUtils.avroToBytes(originalRecord);
+ SerializableIndexedRecord serializableIndexedRecord =
SerializableIndexedRecord.fromAvroBytes(schema, encoded);
+ assertEquals(originalRecord, serializableIndexedRecord.getRecord());
+
+ assertNull(SerializableIndexedRecord.fromAvroBytes(schema, new byte[0]));
+ }
}