This is an automated email from the ASF dual-hosted git repository. blue pushed a commit to branch 0.14.x in repository https://gitbox.apache.org/repos/asf/iceberg.git
commit adb4c2c9dfe7535a500fdd66edaf084cac8238de Author: Karuppayya <[email protected]> AuthorDate: Mon Aug 1 12:36:13 2022 -0700 API: Fix ID assignment in schema merging (#5395) --- .../java/org/apache/iceberg/types/TypeUtil.java | 5 +++-- .../org/apache/iceberg/types/TestTypeUtil.java | 24 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/org/apache/iceberg/types/TypeUtil.java b/api/src/main/java/org/apache/iceberg/types/TypeUtil.java index e4791ee02c..b63908ec16 100644 --- a/api/src/main/java/org/apache/iceberg/types/TypeUtil.java +++ b/api/src/main/java/org/apache/iceberg/types/TypeUtil.java @@ -278,8 +278,9 @@ public class TypeUtil { } public static Schema reassignOrRefreshIds(Schema schema, Schema idSourceSchema) { - AtomicInteger highest = new AtomicInteger(schema.highestFieldId()); - Types.StructType struct = visit(schema, new ReassignIds(idSourceSchema, highest::incrementAndGet)).asStructType(); + AtomicInteger highest = new AtomicInteger(idSourceSchema.highestFieldId()); + Types.StructType struct = + visit(schema, new ReassignIds(idSourceSchema, highest::incrementAndGet)).asStructType(); return new Schema(struct.fields(), refreshIdentifierFields(struct, schema)); } diff --git a/api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java b/api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java index 210efd352f..cd96fe5eaf 100644 --- a/api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java +++ b/api/src/test/java/org/apache/iceberg/types/TestTypeUtil.java @@ -482,4 +482,28 @@ public class TestTypeUtil { Schema actualNoStruct = TypeUtil.selectNot(schema, Sets.newHashSet(2)); Assert.assertEquals(schema.asStruct(), actualNoStruct.asStruct()); } + + @Test + public void testReassignOrRefreshIds() { + Schema schema = + new Schema( + Lists.newArrayList( + required(10, "a", Types.IntegerType.get()), + required(11, "c", Types.IntegerType.get()), + required(12, "B", Types.IntegerType.get())), + Sets.newHashSet(10)); + Schema sourceSchema = + new Schema( + Lists.newArrayList( + required(1, "a", Types.IntegerType.get()), + required(15, "B", Types.IntegerType.get()))); + final Schema actualSchema = TypeUtil.reassignOrRefreshIds(schema, sourceSchema); + final Schema expectedSchema = + new Schema( + Lists.newArrayList( + required(1, "a", Types.IntegerType.get()), + required(16, "c", Types.IntegerType.get()), + required(15, "B", Types.IntegerType.get()))); + Assert.assertEquals(expectedSchema.asStruct(), actualSchema.asStruct()); + } }
