Skip to content

Commit

Permalink
[HUDI-8004] avoid unnecessary record rewriting for merge handler
Browse files Browse the repository at this point in the history
  • Loading branch information
cshuo committed Jan 21, 2025
1 parent 9969b44 commit b5de509
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,18 @@ private static boolean isAtomicSchemasCompatible(Schema oneAtomicType, Schema an
* </ol>
*/
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit b5de509

Please sign in to comment.