diff --git a/parquet-column/src/main/java/org/apache/parquet/schema/GroupType.java b/parquet-column/src/main/java/org/apache/parquet/schema/GroupType.java index 2763b8553b..497a883918 100644 --- a/parquet-column/src/main/java/org/apache/parquet/schema/GroupType.java +++ b/parquet-column/src/main/java/org/apache/parquet/schema/GroupType.java @@ -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 mergeFields(GroupType toMerge) { - return mergeFields(toMerge, true); - } - /** * produces the list of fields resulting from merging toMerge into the fields of this * diff --git a/parquet-column/src/test/java/org/apache/parquet/schema/TestMessageType.java b/parquet-column/src/test/java/org/apache/parquet/schema/TestMessageType.java index d8fae9ac16..45e0be8d88 100644 --- a/parquet-column/src/test/java/org/apache/parquet/schema/TestMessageType.java +++ b/parquet-column/src/test/java/org/apache/parquet/schema/TestMessageType.java @@ -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(