Skip to content

Commit

Permalink
[core] Fix merge schemas equal method issue (#4482)
Browse files Browse the repository at this point in the history
  • Loading branch information
harveyyue authored Nov 11, 2024
1 parent 385be65 commit 70b2d0c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 70b2d0c

Please sign in to comment.