This is an automated email from the ASF dual-hosted git repository.
lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git
The following commit(s) were added to refs/heads/master by this push:
new 70b2d0c58 [core] Fix merge schemas equal method issue (#4482)
70b2d0c58 is described below
commit 70b2d0c58e1a85c9ecf7a22fb9382c7bd13f73fb
Author: Harvey Yue <[email protected]>
AuthorDate: Mon Nov 11 20:26:09 2024 +0800
[core] Fix merge schemas equal method issue (#4482)
---
.../apache/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 30004b53f..d7e21cd65 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 class SchemaMergingUtils {
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 8ad408527..bfc6dd7aa 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.apache.paimon.types.VarCharType;
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 class SchemaMergingUtilsTest {
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.