Skip to content

Commit

Permalink
[core] remove duplicated schema names in list schema in JDBC catalog (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
FANNG1 authored Nov 9, 2024
1 parent 5b07745 commit b8a4def
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -156,7 +157,7 @@ public List<String> listDatabases() {
row -> row.getString(JdbcUtils.DATABASE_NAME),
JdbcUtils.LIST_ALL_PROPERTY_DATABASES_SQL,
catalogKey));
return databases;
return databases.stream().distinct().collect(Collectors.toList());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<String> databases = catalog.listDatabases();
List<String> 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
Expand Down

0 comments on commit b8a4def

Please sign in to comment.