Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -385,20 +385,10 @@ protected Type union(Type toMerge, boolean strict) {
toMerge.getRepetition(),
getName(),
toMerge.getLogicalTypeAnnotation(),
mergeFields(toMerge.asGroupType()),
mergeFields(toMerge.asGroupType(), strict),
getId());
}

/**
* produces the list of fields resulting from merging toMerge into the fields of this
*
* @param toMerge the group containing the fields to merge
* @return the merged list
*/
List<Type> mergeFields(GroupType toMerge) {
return mergeFields(toMerge, true);
}

/**
* produces the list of fields resulting from merging toMerge into the fields of this
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,41 @@ public void testMergeSchema() {
"can not merge type optional fixed_len_byte_array(20) a into optional fixed_len_byte_array(10) a");
}

@Test
public void testNonStrictMergeSchemaWithNestedFields() {
MessageType t1 = new MessageType(
"root1",
new GroupType(REQUIRED, "g", new GroupType(REQUIRED, "g1", new PrimitiveType(OPTIONAL, BINARY, "a"))));
MessageType t2 = new MessageType(
"root2",
new GroupType(
REQUIRED,
"g",
new GroupType(REQUIRED, "g1", new PrimitiveType(OPTIONAL, INT32, "a")),
new PrimitiveType(OPTIONAL, BINARY, "b")));

assertThatThrownBy(() -> t1.union(t2, true))
.isInstanceOf(IncompatibleSchemaModificationException.class)
.hasMessage("can not merge type optional int32 a into optional binary a");

assertThat(t1.union(t2, false))
.isEqualTo(new MessageType(
"root1",
new GroupType(
REQUIRED,
"g",
new GroupType(REQUIRED, "g1", new PrimitiveType(OPTIONAL, BINARY, "a")),
new PrimitiveType(OPTIONAL, BINARY, "b"))));
assertThat(t2.union(t1, false))
.isEqualTo(new MessageType(
"root2",
new GroupType(
REQUIRED,
"g",
new GroupType(REQUIRED, "g1", new PrimitiveType(OPTIONAL, INT32, "a")),
new PrimitiveType(OPTIONAL, BINARY, "b"))));
}

@Test
public void testMergeSchemaWithOriginalType() throws Exception {
MessageType t5 = new MessageType(
Expand Down
Loading