From 70b2d0c58e1a85c9ecf7a22fb9382c7bd13f73fb Mon Sep 17 00:00:00 2001 From: Harvey Yue Date: Mon, 11 Nov 2024 20:26:09 +0800 Subject: [PATCH] [core] Fix merge schemas equal method issue (#4482) --- .../paimon/schema/SchemaMergingUtils.java | 2 +- .../paimon/schema/SchemaMergingUtilsTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/paimon-core/src/main/java/org/apache/paimon/schema/SchemaMergingUtils.java b/paimon-core/src/main/java/org/apache/paimon/schema/SchemaMergingUtils.java index 30004b53fcfb..d7e21cd6562d 100644 --- a/paimon-core/src/main/java/org/apache/paimon/schema/SchemaMergingUtils.java +++ b/paimon-core/src/main/java/org/apache/paimon/schema/SchemaMergingUtils.java @@ -48,7 +48,7 @@ public static TableSchema mergeSchemas( AtomicInteger highestFieldId = new AtomicInteger(currentTableSchema.highestFieldId()); RowType newRowType = mergeSchemas(currentType, targetType, highestFieldId, allowExplicitCast); - if (newRowType == currentType) { + if (newRowType.equals(currentType)) { // It happens if the `targetType` only changes `nullability` but we always respect the // current's. return currentTableSchema; diff --git a/paimon-core/src/test/java/org/apache/paimon/schema/SchemaMergingUtilsTest.java b/paimon-core/src/test/java/org/apache/paimon/schema/SchemaMergingUtilsTest.java index 8ad40852721a..bfc6dd7aa36b 100644 --- a/paimon-core/src/test/java/org/apache/paimon/schema/SchemaMergingUtilsTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/schema/SchemaMergingUtilsTest.java @@ -44,6 +44,7 @@ import org.assertj.core.util.Lists; import org.junit.jupiter.api.Test; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; @@ -92,6 +93,27 @@ public void testMergeTableSchemas() { assertThat(fields.get(4).type() instanceof RowType).isTrue(); } + @Test + public void testMergeTableSchemaNotChanges() { + // Init the table schema + DataField a = new DataField(0, "a", new IntType()); + DataField b = new DataField(1, "b", new DoubleType()); + TableSchema current = + new TableSchema( + 0, + Lists.newArrayList(a, b), + 3, + new ArrayList<>(), + Lists.newArrayList("a"), + new HashMap<>(), + ""); + + // fake the RowType of data with different field sequences + RowType t = new RowType(Lists.newArrayList(b, a)); + TableSchema merged = SchemaMergingUtils.mergeSchemas(current, t, false); + assertThat(merged.id()).isEqualTo(0); + } + @Test public void testMergeSchemas() { // This will test both `mergeSchemas` and `merge` methods.