You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by lz...@apache.org on 2022/10/28 09:01:32 UTC
[flink-table-store] branch master updated: [FLINK-29790] Implement Catalog#getDatabase
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/flink-table-store.git
The following commit(s) were added to refs/heads/master by this push:
new 4b5f7811 [FLINK-29790] Implement Catalog#getDatabase
4b5f7811 is described below
commit 4b5f78119a5d520223f4e726063d588af5522033
Author: Jane Chan <55...@users.noreply.github.com>
AuthorDate: Fri Oct 28 17:01:27 2022 +0800
[FLINK-29790] Implement Catalog#getDatabase
This closes #339
---
.../apache/flink/table/store/connector/FlinkCatalog.java | 15 ++++++++++-----
.../flink/table/store/connector/FlinkCatalogTest.java | 12 ++++++++++++
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/FlinkCatalog.java b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/FlinkCatalog.java
index 63e29b06..d3ada964 100644
--- a/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/FlinkCatalog.java
+++ b/flink-table-store-connector/src/main/java/org/apache/flink/table/store/connector/FlinkCatalog.java
@@ -23,6 +23,7 @@ import org.apache.flink.core.fs.Path;
import org.apache.flink.table.catalog.AbstractCatalog;
import org.apache.flink.table.catalog.CatalogBaseTable;
import org.apache.flink.table.catalog.CatalogDatabase;
+import org.apache.flink.table.catalog.CatalogDatabaseImpl;
import org.apache.flink.table.catalog.CatalogFunction;
import org.apache.flink.table.catalog.CatalogPartition;
import org.apache.flink.table.catalog.CatalogPartitionSpec;
@@ -90,6 +91,15 @@ public class FlinkCatalog extends AbstractCatalog {
return catalog.databaseExists(databaseName);
}
+ @Override
+ public CatalogDatabase getDatabase(String databaseName)
+ throws CatalogException, DatabaseNotExistException {
+ if (databaseExists(databaseName)) {
+ return new CatalogDatabaseImpl(Collections.emptyMap(), null);
+ }
+ throw new DatabaseNotExistException(getName(), databaseName);
+ }
+
@Override
public void createDatabase(String name, CatalogDatabase database, boolean ignoreIfExists)
throws DatabaseAlreadyExistException, CatalogException {
@@ -299,11 +309,6 @@ public class FlinkCatalog extends AbstractCatalog {
// --------------------- unsupported methods ----------------------------
- @Override
- public CatalogDatabase getDatabase(String databaseName) throws CatalogException {
- throw new UnsupportedOperationException();
- }
-
@Override
public final void alterDatabase(
String name, CatalogDatabase newDatabase, boolean ignoreIfNotExists)
diff --git a/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/FlinkCatalogTest.java b/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/FlinkCatalogTest.java
index 66412a77..e7a6d6fe 100644
--- a/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/FlinkCatalogTest.java
+++ b/flink-table-store-connector/src/test/java/org/apache/flink/table/store/connector/FlinkCatalogTest.java
@@ -24,6 +24,7 @@ import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.Schema;
import org.apache.flink.table.catalog.Catalog;
import org.apache.flink.table.catalog.CatalogBaseTable;
+import org.apache.flink.table.catalog.CatalogDatabase;
import org.apache.flink.table.catalog.CatalogDatabaseImpl;
import org.apache.flink.table.catalog.CatalogTable;
import org.apache.flink.table.catalog.Column;
@@ -323,6 +324,17 @@ public class FlinkCatalogTest {
Assert.assertTrue(catalog.databaseExists("db1"));
}
+ @Test
+ public void testGetDatabase() throws Exception {
+ catalog.createDatabase(path1.getDatabaseName(), null, false);
+ CatalogDatabase database = catalog.getDatabase(path1.getDatabaseName());
+ assertThat(database.getProperties()).isEmpty();
+ assertThat(database.getDescription()).isEmpty();
+ assertThatThrownBy(() -> catalog.getDatabase(nonExistDbPath.getDatabaseName()))
+ .isInstanceOf(DatabaseNotExistException.class)
+ .hasMessageContaining("Database non does not exist in Catalog test-catalog.");
+ }
+
@Test
public void testDropDb_DatabaseNotExist_Ignore() throws Exception {
catalog.dropDatabase("db1", true, false);