This is an automated email from the ASF dual-hosted git repository. yuzelin pushed a commit to branch release-1.4 in repository https://gitbox.apache.org/repos/asf/paimon.git
commit 3579ba16634a3c7a0b127ccbd96443db8952eb43 Author: Weitai Li <[email protected]> AuthorDate: Thu Apr 9 22:23:54 2026 +0800 [core] Add hashCode to AbstractFileStoreTable for consistency with equals (#7616) --- .../paimon/table/AbstractFileStoreTable.java | 5 ++++ .../paimon/table/AppendOnlySimpleTableTest.java | 27 ++++++++++++++++++++++ .../paimon/table/PrimaryKeySimpleTableTest.java | 27 ++++++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java b/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java index f8a6b1722f..522d25c7d3 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java @@ -796,4 +796,9 @@ abstract class AbstractFileStoreTable implements FileStoreTable { AbstractFileStoreTable that = (AbstractFileStoreTable) o; return Objects.equals(path, that.path) && Objects.equals(tableSchema, that.tableSchema); } + + @Override + public int hashCode() { + return Objects.hash(path, tableSchema); + } } diff --git a/paimon-core/src/test/java/org/apache/paimon/table/AppendOnlySimpleTableTest.java b/paimon-core/src/test/java/org/apache/paimon/table/AppendOnlySimpleTableTest.java index ed6f8349e0..30ccc652a0 100644 --- a/paimon-core/src/test/java/org/apache/paimon/table/AppendOnlySimpleTableTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/table/AppendOnlySimpleTableTest.java @@ -1565,6 +1565,33 @@ public class AppendOnlySimpleTableTest extends SimpleTableTestBase { } } + @Test + public void testEqualsAndHashCode() throws Exception { + // Test same table equals and hashCode consistency + FileStoreTable table1 = createFileStoreTable(); + FileStoreTable table2 = table1.copy(table1.schema()); + assertThat(table1.equals(table2)).isTrue(); + assertThat(table1.hashCode()).isEqualTo(table2.hashCode()); + + // Test with different options + Map<String, String> optionsWithMock = new HashMap<>(table1.schema().options()); + optionsWithMock.put("mockKey", "mockValue"); + TableSchema schemaWithMock = table1.schema().copy(optionsWithMock); + FileStoreTable tableWithMock = table1.copy(schemaWithMock); + + assertThat(table1.equals(tableWithMock)).isFalse(); + assertThat(table1.hashCode()).isNotEqualTo(tableWithMock.hashCode()); + + // Test same options should be equal + Map<String, String> sameOptionsWithMock = new HashMap<>(table1.schema().options()); + sameOptionsWithMock.put("mockKey", "mockValue"); + TableSchema sameSchemaWithMock = table1.schema().copy(sameOptionsWithMock); + FileStoreTable sameTableWithMock = table1.copy(sameSchemaWithMock); + + assertThat(tableWithMock.equals(sameTableWithMock)).isTrue(); + assertThat(tableWithMock.hashCode()).isEqualTo(sameTableWithMock.hashCode()); + } + private void writeData() throws Exception { writeData(options -> {}); } diff --git a/paimon-core/src/test/java/org/apache/paimon/table/PrimaryKeySimpleTableTest.java b/paimon-core/src/test/java/org/apache/paimon/table/PrimaryKeySimpleTableTest.java index d920cd0a07..9401cce832 100644 --- a/paimon-core/src/test/java/org/apache/paimon/table/PrimaryKeySimpleTableTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/table/PrimaryKeySimpleTableTest.java @@ -2473,6 +2473,33 @@ public class PrimaryKeySimpleTableTest extends SimpleTableTestBase { "1|10|100|binary|varbinary|mapKey:mapVal|multiset")); } + @Test + public void testEqualsAndHashCode() throws Exception { + // Test same table equals and hashCode consistency + FileStoreTable table1 = createFileStoreTable(); + FileStoreTable table2 = table1.copy(table1.schema()); + assertThat(table1.equals(table2)).isTrue(); + assertThat(table1.hashCode()).isEqualTo(table2.hashCode()); + + // Test with different options + Map<String, String> optionsWithMock = new HashMap<>(table1.schema().options()); + optionsWithMock.put("mockKey", "mockValue"); + TableSchema schemaWithMock = table1.schema().copy(optionsWithMock); + FileStoreTable tableWithMock = table1.copy(schemaWithMock); + + assertThat(table1.equals(tableWithMock)).isFalse(); + assertThat(table1.hashCode()).isNotEqualTo(tableWithMock.hashCode()); + + // Test same options should be equal + Map<String, String> sameOptionsWithMock = new HashMap<>(table1.schema().options()); + sameOptionsWithMock.put("mockKey", "mockValue"); + TableSchema sameSchemaWithMock = table1.schema().copy(sameOptionsWithMock); + FileStoreTable sameTableWithMock = table1.copy(sameSchemaWithMock); + + assertThat(tableWithMock.equals(sameTableWithMock)).isTrue(); + assertThat(tableWithMock.hashCode()).isEqualTo(sameTableWithMock.hashCode()); + } + private void assertReadChangelog(int id, FileStoreTable table) throws Exception { // read the changelog at #{id} table = table.copy(singletonMap(CoreOptions.SCAN_SNAPSHOT_ID.key(), String.valueOf(id)));
