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 e4a5fe8ecf15..f78accbf89c4 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 @@ private static boolean isAtomicSchemasCompatible(Schema oneAtomicType, Schema an * */ public static boolean isStrictProjectionOf(Schema sourceSchema, Schema targetSchema) { - return isProjectionOfInternal(sourceSchema, targetSchema, Objects::equals); + return isProjectionOfInternal(sourceSchema, targetSchema, AvroSchemaUtils::isAtomicTypeStrictProject); + } + + private static boolean isAtomicTypeStrictProject(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 d13bfe5a69ac..b40e88b50ef9 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 @@ -46,6 +46,19 @@ public class TestAvroSchemaUtils { + " \"name\": \"number\",\n" + " \"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" @@ -75,6 +88,19 @@ public class TestAvroSchemaUtils { + " \"name\": \"number\",\n" + " \"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"