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 9df84ac09ba0..5743b8a2a32b 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 @@ -25,6 +25,7 @@ import org.apache.paimon.options.Options; import org.apache.paimon.schema.Schema; import org.apache.paimon.schema.SchemaChange; +import org.apache.paimon.table.FileStoreTable; import org.apache.paimon.table.FormatTable; import org.apache.paimon.table.Table; import org.apache.paimon.types.DataField; @@ -146,6 +147,57 @@ public void testCreateDatabase() throws Exception { .doesNotThrowAnyException(); } + @Test + public void testAlterDatabase() throws Exception { + if (supportsAlterDatabase()) { + // Alter database + String databaseName = "db_to_alter"; + catalog.createDatabase(databaseName, false); + String key = "key1"; + String key2 = "key2"; + // Add property + catalog.alterDatabase( + databaseName, + Lists.newArrayList( + PropertyChange.setProperty(key, "value"), + PropertyChange.setProperty(key2, "value")), + false); + Database db = catalog.getDatabase(databaseName); + assertEquals("value", db.options().get(key)); + assertEquals("value", db.options().get(key2)); + // Update property + catalog.alterDatabase( + databaseName, + Lists.newArrayList( + PropertyChange.setProperty(key, "value1"), + PropertyChange.setProperty(key2, "value1")), + false); + db = catalog.getDatabase(databaseName); + assertEquals("value1", db.options().get(key)); + assertEquals("value1", db.options().get(key2)); + // remove property + catalog.alterDatabase( + databaseName, + Lists.newArrayList( + PropertyChange.removeProperty(key), + PropertyChange.removeProperty(key2)), + false); + db = catalog.getDatabase(databaseName); + assertEquals(false, db.options().containsKey(key)); + assertEquals(false, db.options().containsKey(key2)); + // Remove non-existent property + catalog.alterDatabase( + databaseName, + Lists.newArrayList( + PropertyChange.removeProperty(key), + PropertyChange.removeProperty(key2)), + false); + db = catalog.getDatabase(databaseName); + assertEquals(false, db.options().containsKey(key)); + assertEquals(false, db.options().containsKey(key2)); + } + } + @Test public void testDropDatabase() throws Exception { // Drop database deletes the database when it exists and there are no tables @@ -193,6 +245,10 @@ public void testListTables() throws Exception { tables = catalog.listTables("test_db"); assertThat(tables).containsExactlyInAnyOrder("table1", "table2", "table3"); + + // List tables throws DatabaseNotExistException when the database does not exist + assertThatExceptionOfType(Catalog.DatabaseNotExistException.class) + .isThrownBy(() -> catalog.listTables("non_existing_db")); } @Test @@ -317,8 +373,8 @@ public void testGetTable() throws Exception { catalog.createTable(identifier, DEFAULT_TABLE_SCHEMA, false); Table systemTable = catalog.getTable(Identifier.create("test_db", "test_table$snapshots")); assertThat(systemTable).isNotNull(); - Table dataTable = catalog.getTable(identifier); - assertThat(dataTable).isNotNull(); + FileStoreTable dataTable = (FileStoreTable) catalog.getTable(identifier); + assertThat(dataTable.schema().toSchema().fields()).isEqualTo(DEFAULT_TABLE_SCHEMA.fields()); // Get system table throws Exception when table contains multiple '$' separator assertThatExceptionOfType(IllegalArgumentException.class) @@ -956,49 +1012,7 @@ public void testTableUUID() throws Exception { .isGreaterThan(0); } - protected void alterDatabaseWhenSupportAlter() throws Exception { - // Alter database - String databaseName = "db_to_alter"; - catalog.createDatabase(databaseName, false); - String key = "key1"; - String key2 = "key2"; - // Add property - catalog.alterDatabase( - databaseName, - Lists.newArrayList( - PropertyChange.setProperty(key, "value"), - PropertyChange.setProperty(key2, "value")), - false); - Database db = catalog.getDatabase(databaseName); - assertEquals("value", db.options().get(key)); - assertEquals("value", db.options().get(key2)); - // Update property - catalog.alterDatabase( - databaseName, - Lists.newArrayList( - PropertyChange.setProperty(key, "value1"), - PropertyChange.setProperty(key2, "value1")), - false); - db = catalog.getDatabase(databaseName); - assertEquals("value1", db.options().get(key)); - assertEquals("value1", db.options().get(key2)); - // remove property - catalog.alterDatabase( - databaseName, - Lists.newArrayList( - PropertyChange.removeProperty(key), PropertyChange.removeProperty(key2)), - false); - db = catalog.getDatabase(databaseName); - assertEquals(false, db.options().containsKey(key)); - assertEquals(false, db.options().containsKey(key2)); - // Remove non-existent property - catalog.alterDatabase( - databaseName, - Lists.newArrayList( - PropertyChange.removeProperty(key), PropertyChange.removeProperty(key2)), - false); - db = catalog.getDatabase(databaseName); - assertEquals(false, db.options().containsKey(key)); - assertEquals(false, db.options().containsKey(key2)); + protected boolean supportsAlterDatabase() { + return false; } } diff --git a/paimon-core/src/test/java/org/apache/paimon/jdbc/JdbcCatalogTest.java b/paimon-core/src/test/java/org/apache/paimon/jdbc/JdbcCatalogTest.java index 51e2bf5c779d..0dea9209036d 100644 --- a/paimon-core/src/test/java/org/apache/paimon/jdbc/JdbcCatalogTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/jdbc/JdbcCatalogTest.java @@ -117,8 +117,8 @@ public void testSerializeTable() throws Exception { }); } - @Test - public void testAlterDatabase() throws Exception { - this.alterDatabaseWhenSupportAlter(); + @Override + protected boolean supportsAlterDatabase() { + return true; } } diff --git a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java index 8b53c61f83e6..48ebda9542d9 100644 --- a/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java +++ b/paimon-core/src/test/java/org/apache/paimon/rest/RESTCatalogTest.java @@ -77,7 +77,7 @@ public void testInitFailWhenDefineWarehouse() { } @Test - public void testAuthFail() { + void testAuthFail() { Options options = new Options(); options.set(RESTCatalogOptions.URI, restCatalogServer.getUrl()); options.set(RESTCatalogOptions.TOKEN, "aaaaa"); diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/RESTCatalogITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/RESTCatalogITCase.java index 221f6e74d8fa..b100305d751b 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/RESTCatalogITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/RESTCatalogITCase.java @@ -40,7 +40,7 @@ public class RESTCatalogITCase extends CatalogITCaseBase { private static final String databaseName = "mydb"; private static final String tableName = "t1"; - RESTCatalogServer RESTCatalogServer; + RESTCatalogServer restCatalogServer; private String serverUrl; protected String warehouse; @TempDir java.nio.file.Path tempFile; @@ -49,9 +49,9 @@ public class RESTCatalogITCase extends CatalogITCaseBase { public void before() throws IOException { String initToken = "init_token"; warehouse = tempFile.toUri().toString(); - RESTCatalogServer = new RESTCatalogServer(warehouse, initToken); - RESTCatalogServer.start(); - serverUrl = RESTCatalogServer.getUrl(); + restCatalogServer = new RESTCatalogServer(warehouse, initToken); + restCatalogServer.start(); + serverUrl = restCatalogServer.getUrl(); super.before(); sql(String.format("CREATE DATABASE %s", databaseName)); sql(String.format("CREATE TABLE %s.%s (a STRING, b DOUBLE)", databaseName, tableName)); @@ -61,7 +61,7 @@ public void before() throws IOException { public void after() throws IOException { sql(String.format("DROP TABLE %s.%s", databaseName, tableName)); sql(String.format("DROP DATABASE %s", databaseName)); - RESTCatalogServer.shutdown(); + restCatalogServer.shutdown(); } @Test @@ -81,13 +81,14 @@ public void testAlterTable() { sql(String.format("ALTER TABLE %s.%s ADD e INT AFTER b", databaseName, tableName)); sql(String.format("ALTER TABLE %s.%s DROP b", databaseName, tableName)); sql(String.format("ALTER TABLE %s.%s RENAME a TO a1", databaseName, tableName)); + sql(String.format("ALTER TABLE %s.%s MODIFY e DOUBLE", databaseName, tableName)); List result = sql(String.format("SHOW CREATE TABLE %s.%s", databaseName, tableName)); assertThat(result.toString()) .contains( String.format( "CREATE TABLE `PAIMON`.`%s`.`%s` (\n" + " `a1` VARCHAR(2147483647),\n" - + " `e` INT", + + " `e` DOUBLE", databaseName, tableName)); } diff --git a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java index d96fac808cab..e185e5acbf50 100644 --- a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java +++ b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java @@ -172,11 +172,6 @@ private void testHiveConfDirFromEnvImpl() { assertThat(hiveConf.get("hive.metastore.uris")).isEqualTo("dummy-hms"); } - @Test - public void testAlterDatabase() throws Exception { - this.alterDatabaseWhenSupportAlter(); - } - @Test public void testAddHiveTableParameters() { try { @@ -503,4 +498,9 @@ public void testPartitionTable() throws Exception { // hive catalog list partitions from filesystem, so here return empty. assertThat(catalog.listPartitions(identifier)).isEmpty(); } + + @Override + protected boolean supportsAlterDatabase() { + return true; + } }