Skip to content

Commit

Permalink
fixed spotbug issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gaojieliu committed Oct 12, 2023
1 parent 49f5023 commit 2b04244
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,22 @@ private static Schema unionSchema(Schema s1, Schema s2) {
return Schema.createUnion(combinedSchema);
}

private static void copyFieldProperties(FieldBuilder fieldBuilder, Schema.Field field) {
AvroCompatibilityHelper.getAllPropNames(field).forEach(k -> {
String propValue = AvroCompatibilityHelper.getFieldPropAsJsonString(field, k);
if (propValue != null) {
fieldBuilder.addProp(k, propValue);
}
});
}

private static FieldBuilder deepCopySchemaField(Schema.Field field) {
FieldBuilder fieldBuilder = AvroCompatibilityHelper.newField(null)
.setName(field.name())
.setSchema(field.schema())
.setDoc(field.doc())
.setOrder(field.order());
field.getObjectProps().forEach((k, ignored) -> {
String propValue = field.getProp(k);
if (propValue != null) {
fieldBuilder.addProp(k, propValue);
}
});
copyFieldProperties(fieldBuilder, field);

// set default as AvroCompatibilityHelper builder might drop defaults if there is type mismatch
if (field.hasDefaultValue()) {
Expand All @@ -139,12 +143,7 @@ private static List<Schema.Field> mergeFieldSchemas(Schema s1, Schema s2) {
fieldBuilder.setSchema(generateSuperSetSchema(f1.schema(), f2.schema()))
.setDoc(f1.doc() != null ? f1.doc() : f2.doc());
// merge props from f2
f2.getObjectProps().forEach((k, ignored) -> {
String propValue = f2.getProp(k);
if (propValue != null) {
fieldBuilder.addProp(k, propValue);
}
});
copyFieldProperties(fieldBuilder, f2);
}
fields.add(fieldBuilder.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,10 @@ public void testSupersetSchemaContainsMergeFieldProps() {
Schema.Field intField = supersetSchema.getField("int_field");
Schema.Field stringField = supersetSchema.getField("string_field");

Assert.assertEquals(intField.getProp("prop1"), "prop1_v2");
Assert.assertEquals(intField.getProp("prop2"), "prop2_v1");
Assert.assertEquals(stringField.getProp("prop3"), "prop3_v1");
Assert.assertEquals(stringField.getProp("prop2"), "prop2_v2");
Assert.assertEquals(intField.getProp("prop1"), "\"prop1_v2\"");
Assert.assertEquals(intField.getProp("prop2"), "\"prop2_v1\"");
Assert.assertEquals(stringField.getProp("prop3"), "\"prop3_v1\"");
Assert.assertEquals(stringField.getProp("prop2"), "\"prop2_v2\"");
}

@Test
Expand Down

0 comments on commit 2b04244

Please sign in to comment.