diff --git a/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java b/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java index c80f8e3a53fc..778bc591fe89 100644 --- a/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java +++ b/paimon-core/src/main/java/org/apache/paimon/jdbc/JdbcCatalog.java @@ -52,6 +52,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; import static org.apache.paimon.jdbc.JdbcCatalogLock.acquireTimeout; import static org.apache.paimon.jdbc.JdbcCatalogLock.checkMaxSleep; @@ -156,7 +157,7 @@ public List listDatabases() { row -> row.getString(JdbcUtils.DATABASE_NAME), JdbcUtils.LIST_ALL_PROPERTY_DATABASES_SQL, catalogKey)); - return databases; + return databases.stream().distinct().collect(Collectors.toList()); } @Override diff --git a/paimon-core/src/test/java/org/apache/paimon/catalog/CatalogTestBase.java b/paimon-core/src/test/java/org/apache/paimon/catalog/CatalogTestBase.java index 643e1372b614..24eefbcb65d2 100644 --- a/paimon-core/src/test/java/org/apache/paimon/catalog/CatalogTestBase.java +++ b/paimon-core/src/test/java/org/apache/paimon/catalog/CatalogTestBase.java @@ -37,6 +37,7 @@ import org.apache.paimon.shade.guava30.com.google.common.collect.Maps; import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -46,6 +47,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; import static org.apache.paimon.testutils.assertj.PaimonAssertions.anyCauseMatches; import static org.assertj.core.api.Assertions.assertThat; @@ -111,6 +113,18 @@ public void testListDatabases() throws Exception { assertThat(databases).contains("db1", "db2", "db3"); } + @Test + public void testDuplicatedDatabaseAfterCreatingTable() throws Exception { + catalog.createDatabase("test_db", false); + Identifier identifier = Identifier.create("test_db", "new_table"); + Schema schema = Schema.newBuilder().column("pk1", DataTypes.INT()).build(); + catalog.createTable(identifier, schema, false); + + List databases = catalog.listDatabases(); + List distinctDatabases = databases.stream().distinct().collect(Collectors.toList()); + Assertions.assertEquals(distinctDatabases.size(), databases.size()); + } + @Test public void testCreateDatabase() throws Exception { // Create database creates a new database when it does not exist