This is an automated email from the ASF dual-hosted git repository.
danny0405 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 02472c91aac [HUDI-8004] Avoid unnecessary record rewrite during
merging with base file (#12683)
02472c91aac is described below
commit 02472c91aac1892d76602795c3f816b58e9c90f7
Author: Shuo Cheng <[email protected]>
AuthorDate: Tue Jan 28 11:03:14 2025 +0800
[HUDI-8004] Avoid unnecessary record rewrite during merging with base file
(#12683)
---
.../java/org/apache/hudi/avro/AvroSchemaUtils.java | 13 ++++++++++-
.../org/apache/hudi/avro/TestAvroSchemaUtils.java | 26 ++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git
a/hudi-common/src/main/java/org/apache/hudi/avro/AvroSchemaUtils.java
b/hudi-common/src/main/java/org/apache/hudi/avro/AvroSchemaUtils.java
index e4a5fe8ecf1..28dc9743ad7 100644
--- a/hudi-common/src/main/java/org/apache/hudi/avro/AvroSchemaUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/avro/AvroSchemaUtils.java
@@ -174,7 +174,18 @@ public class AvroSchemaUtils {
* </ol>
*/
public static boolean isStrictProjectionOf(Schema sourceSchema, Schema
targetSchema) {
- return isProjectionOfInternal(sourceSchema, targetSchema, Objects::equals);
+ return isProjectionOfInternal(sourceSchema, targetSchema,
AvroSchemaUtils::isAtomicTypeEquals);
+ }
+
+ private static boolean isAtomicTypeEquals(Schema source, Schema target) {
+ // ignore name/namespace for FIXED type
+ if (source.getType() == Schema.Type.FIXED && target.getType() ==
Schema.Type.FIXED) {
+ return source.getLogicalType().equals(target.getLogicalType())
+ && source.getFixedSize() == target.getFixedSize()
+ && source.getObjectProps().equals(target.getObjectProps());
+ } else {
+ return Objects.equals(source, target);
+ }
}
private static boolean isProjectionOfInternal(Schema sourceSchema,
diff --git
a/hudi-common/src/test/java/org/apache/hudi/avro/TestAvroSchemaUtils.java
b/hudi-common/src/test/java/org/apache/hudi/avro/TestAvroSchemaUtils.java
index d13bfe5a69a..27d29f83f05 100644
--- a/hudi-common/src/test/java/org/apache/hudi/avro/TestAvroSchemaUtils.java
+++ b/hudi-common/src/test/java/org/apache/hudi/avro/TestAvroSchemaUtils.java
@@ -47,6 +47,19 @@ public class TestAvroSchemaUtils {
+ " \"type\": [\"null\", \"int\"]\n"
+ " },\n"
+ " {\n"
+ + " \"name\" : \"f1\",\n"
+ + " \"type\" : [ \"null\", {\n"
+ + " \"type\" : \"fixed\",\n"
+ + " \"name\" : \"f1\",\n"
+ + " \"namespace\" : \"\",\n"
+ + " \"size\" : 5,\n"
+ + " \"logicalType\" : \"decimal\",\n"
+ + " \"precision\" : 10,\n"
+ + " \"scale\" : 2\n"
+ + " }],\n"
+ + " \"default\" : null\n"
+ + " },\n"
+ + " {\n"
+ " \"name\": \"nested_record\",\n"
+ " \"type\": {\n"
+ " \"name\": \"nested\",\n"
@@ -76,6 +89,19 @@ public class TestAvroSchemaUtils {
+ " \"type\": [\"null\", \"int\"]\n"
+ " },\n"
+ " {\n"
+ + " \"name\" : \"f1\",\n"
+ + " \"type\" : [ \"null\", {\n"
+ + " \"type\" : \"fixed\",\n"
+ + " \"name\" : \"fixed\",\n"
+ + " \"namespace\" : \"example.schema.source.f1\",\n"
+ + " \"size\" : 5,\n"
+ + " \"logicalType\" : \"decimal\",\n"
+ + " \"precision\" : 10,\n"
+ + " \"scale\" : 2\n"
+ + " }],\n"
+ + " \"default\" : null\n"
+ + " },\n"
+ + " {\n"
+ " \"name\": \"nested_record\",\n"
+ " \"type\": {\n"
+ " \"name\": \"nested\",\n"