Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#2434] Improvement: if DropXXX success, return true, if not exists return false (#3222)

charliecheng630992c787e44e5
diff --git a/api/src/main/java/com/datastrato/gravitino/SupportsMetalakes.java b/api/src/main/java/com/datastrato/gravitino/SupportsMetalakes.java
index 9c08e7fe9d..c8e4c10881 100644
--- a/api/src/main/java/com/datastrato/gravitino/SupportsMetalakes.java
+++ b/api/src/main/java/com/datastrato/gravitino/SupportsMetalakes.java
@@ -75,7 +75,7 @@ public interface SupportsMetalakes {
* Drop a metalake with specified identifier.
*
* @param name The identifier of the metalake.
- * @return True if the metalake was dropped, false otherwise.
+ * @return True if the metalake was dropped, false if the metalake does not exist.
*/
boolean dropMetalake(String name);
}
diff --git a/api/src/main/java/com/datastrato/gravitino/rel/SupportsPartitions.java b/api/src/main/java/com/datastrato/gravitino/rel/SupportsPartitions.java
index 024ea0473b..9cc3c1b97d 100644
--- a/api/src/main/java/com/datastrato/gravitino/rel/SupportsPartitions.java
+++ b/api/src/main/java/com/datastrato/gravitino/rel/SupportsPartitions.java
@@ -80,7 +80,7 @@ public interface SupportsPartitions {
* Drop a partition with specified name.
*
* @param partitionName the name of the partition
- * @return true if a partition was deleted.
+ * @return true if a partition was deleted successfully, false if the partition does not exist.
*/
boolean dropPartition(String partitionName);
diff --git a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java
index a46d1094d5..b130ac3977 100644
--- a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java
+++ b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/TestHadoopCatalogOperations.java
@@ -311,8 +311,8 @@ public class TestHadoopCatalogOperations {
Assertions.assertFalse(fs.exists(schemaPath));
// Test drop empty schema
- Assertions.assertFalse(ops.dropSchema(id, true));
- Assertions.assertFalse(ops.dropSchema(id, false));
+ Assertions.assertFalse(ops.dropSchema(id, true), "schema should be non-existent");
+ Assertions.assertFalse(ops.dropSchema(id, false), "schema should be non-existent");
}
}
@@ -364,6 +364,9 @@ public class TestHadoopCatalogOperations {
} else {
Assertions.assertTrue(fs.exists(expectedPath));
}
+
+ // Test drop non-existent fileset
+ Assertions.assertFalse(ops.dropFileset(filesetIdent), "fileset should be non-existent");
}
}
diff --git a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java
index 277652b8ed..e79432f209 100644
--- a/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java
+++ b/catalogs/catalog-hadoop/src/test/java/com/datastrato/gravitino/catalog/hadoop/integration/test/HadoopCatalogIT.java
@@ -67,8 +67,10 @@ public class HadoopCatalogIT extends AbstractIT {
@AfterAll
public static void stop() throws IOException {
+ Catalog catalog = metalake.loadCatalog(catalogName);
+ catalog.asSchemas().dropSchema(schemaName, true);
+ metalake.dropCatalog(catalogName);
client.dropMetalake(metalakeName);
-
if (hdfs != null) {
hdfs.close();
}
diff --git a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java
index aea817adba..c095e29218 100644
--- a/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java
+++ b/catalogs/catalog-hive/src/main/java/com/datastrato/gravitino/catalog/hive/HiveCatalogOperations.java
@@ -455,7 +455,7 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemas
*
* @param ident The identifier of the schema to drop.
* @param cascade If set to true, drops all the tables in the schema as well.
- * @return true if the schema was dropped successfully, false otherwise.
+ * @return true if the schema was dropped successfully, false if the schema does not exist.
* @throws NonEmptySchemaException If the schema is not empty and 'cascade' is set to false.
*/
@Override
@@ -987,10 +987,14 @@ public class HiveCatalogOperations implements CatalogOperations, SupportsSchemas
*/
@Override
public boolean dropTable(NameIdentifier tableIdent) {
- if (isExternalTable(tableIdent)) {
- return dropHiveTable(tableIdent, false, false);
- } else {
- return dropHiveTable(tableIdent, true, false);
+ try {
+ if (isExternalTable(tableIdent)) {
+ return dropHiveTable(tableIdent, false, false);
+ } else {
+ return dropHiveTable(tableIdent, true, false);
+ }
+ } catch (NoSuchTableException e) {
+ return false;
}
}
diff --git a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveSchema.java b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveSchema.java
index 5dfc1679ba..db067fc965 100644
--- a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveSchema.java
+++ b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveSchema.java
@@ -156,5 +156,7 @@ public class TestHiveSchema extends MiniHiveMetastoreService {
Assertions.assertTrue(catalogOperations.schemaExists(ident));
catalogOperations.dropSchema(ident, true);
Assertions.assertFalse(catalogOperations.schemaExists(ident));
+ Assertions.assertFalse(
+ catalogOperations.dropSchema(ident, true), "schema should not be exists");
}
}
diff --git a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveTable.java b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveTable.java
index edd5fb5f97..c4b9306db6 100644
--- a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveTable.java
+++ b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveTable.java
@@ -320,6 +320,8 @@ public class TestHiveTable extends MiniHiveMetastoreService {
Assertions.assertTrue(hiveCatalogOperations.tableExists(tableIdentifier));
hiveCatalogOperations.dropTable(tableIdentifier);
Assertions.assertFalse(hiveCatalogOperations.tableExists(tableIdentifier));
+ Assertions.assertFalse(
+ hiveCatalogOperations.dropTable(tableIdentifier), "table should not be exists");
}
@Test
diff --git a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveTableOperations.java b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveTableOperations.java
index f2423c8040..501095a0ef 100644
--- a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveTableOperations.java
+++ b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/TestHiveTableOperations.java
@@ -271,7 +271,9 @@ public class TestHiveTableOperations extends MiniHiveMetastoreService {
Assertions.assertEquals(
"Error partition format: does_not_exist_partition", exception5.getMessage());
- Assertions.assertFalse(hiveTable.supportPartitions().dropPartition("city=not_exist"));
+ Assertions.assertFalse(
+ hiveTable.supportPartitions().dropPartition("city=not_exist"),
+ "partition should be non-existent");
}
@Test
diff --git a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/integration/test/CatalogHiveIT.java b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/integration/test/CatalogHiveIT.java
index 2c59f3a365..39d8a45aa6 100644
--- a/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/integration/test/CatalogHiveIT.java
+++ b/catalogs/catalog-hive/src/test/java/com/datastrato/gravitino/catalog/hive/integration/test/CatalogHiveIT.java
@@ -199,6 +199,17 @@ public class CatalogHiveIT extends AbstractIT {
@AfterAll
public static void stop() throws IOException {
+ Arrays.stream(catalog.asSchemas().listSchemas())
+ .filter(ident -> !ident.name().equals("default"))
+ .forEach(
+ (ident -> {
+ catalog.asSchemas().dropSchema(ident.name(), true);
+ }));
+ Arrays.stream(metalake.listCatalogs())
+ .forEach(
+ (ident -> {
+ metalake.dropCatalog(ident.name());
+ }));
if (client != null) {
client.dropMetalake(metalakeName);
}
diff --git a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java
index cd0b6197ba..340347fa61 100644
--- a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java
+++ b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/JdbcCatalogOperations.java
@@ -239,13 +239,12 @@ public class JdbcCatalogOperations implements CatalogOperations, SupportsSchemas
*
* @param ident The identifier of the schema to drop.
* @param cascade If set to true, drops all the tables in the schema as well.
- * @return true if the schema was dropped successfully, false otherwise.
+ * @return true if the schema is successfully dropped; false if the schema does not exist.
* @throws NonEmptySchemaException If the schema is not empty and 'cascade' is set to false.
*/
@Override
public boolean dropSchema(NameIdentifier ident, boolean cascade) throws NonEmptySchemaException {
- databaseOperation.delete(ident.name(), cascade);
- return true;
+ return databaseOperation.delete(ident.name(), cascade);
}
/**
@@ -342,8 +341,7 @@ public class JdbcCatalogOperations implements CatalogOperations, SupportsSchemas
@Override
public boolean dropTable(NameIdentifier tableIdent) {
String databaseName = NameIdentifier.of(tableIdent.namespace().levels()).name();
- tableOperation.drop(databaseName, tableIdent.name());
- return true;
+ return tableOperation.drop(databaseName, tableIdent.name());
}
/**
diff --git a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/DatabaseOperation.java b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/DatabaseOperation.java
index a58c012e8b..db424b8680 100644
--- a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/DatabaseOperation.java
+++ b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/DatabaseOperation.java
@@ -37,8 +37,9 @@ public interface DatabaseOperation {
/**
* @param databaseName The name of the database to check.
* @param cascade If set to true, drops all the tables in the database as well.
+ * @return true if the database is successfully deleted; false if the database does not exist.
*/
- void delete(String databaseName, boolean cascade) throws NoSuchSchemaException;
+ boolean delete(String databaseName, boolean cascade);
/** @return The list name of databases. */
List<String> listDatabases();
diff --git a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/JdbcDatabaseOperations.java b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/JdbcDatabaseOperations.java
index 6c0be7351c..7b13d4f354 100644
--- a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/JdbcDatabaseOperations.java
+++ b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/JdbcDatabaseOperations.java
@@ -49,14 +49,15 @@ public abstract class JdbcDatabaseOperations implements DatabaseOperation {
}
@Override
- public void delete(String databaseName, boolean cascade) throws NoSuchSchemaException {
+ public boolean delete(String databaseName, boolean cascade) {
LOG.info("Beginning to drop database {}", databaseName);
- try (final Connection connection = getConnection()) {
- JdbcConnectorUtils.executeUpdate(connection, generateDropDatabaseSql(databaseName, cascade));
+ try {
+ dropDatabase(databaseName, cascade);
LOG.info("Finished dropping database {}", databaseName);
- } catch (final SQLException se) {
- throw this.exceptionMapper.toGravitinoException(se);
+ } catch (NoSuchSchemaException e) {
+ return false;
}
+ return true;
}
@Override
@@ -77,6 +78,14 @@ public abstract class JdbcDatabaseOperations implements DatabaseOperation {
}
}
+ protected void dropDatabase(String databaseName, boolean cascade) {
+ try (final Connection connection = getConnection()) {
+ JdbcConnectorUtils.executeUpdate(connection, generateDropDatabaseSql(databaseName, cascade));
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
/**
* @param databaseName The name of the database.
* @param comment The comment of the database.
diff --git a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/JdbcTableOperations.java b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
index 3f7e1cbda8..126e792905 100644
--- a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
+++ b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
@@ -96,14 +96,17 @@ public abstract class JdbcTableOperations implements TableOperation {
}
@Override
- public void drop(String databaseName, String tableName) throws NoSuchTableException {
+ public boolean drop(String databaseName, String tableName) {
LOG.info("Attempting to delete table {} from database {}", tableName, databaseName);
- try (Connection connection = getConnection(databaseName)) {
- JdbcConnectorUtils.executeUpdate(connection, generateDropTableSql(tableName));
+ try {
+ dropTable(databaseName, tableName);
LOG.info("Deleted table {} from database {}", tableName, databaseName);
- } catch (final SQLException se) {
- throw this.exceptionMapper.toGravitinoException(se);
+ } catch (NoSuchTableException e) {
+ return false;
+ } catch (NoSuchSchemaException e) {
+ return false;
}
+ return true;
}
@Override
@@ -259,6 +262,15 @@ public abstract class JdbcTableOperations implements TableOperation {
}
}
+ protected void dropTable(String databaseName, String tableName) {
+ LOG.info("Attempting to delete table {} from database {}", tableName, databaseName);
+ try (Connection connection = getConnection(databaseName)) {
+ JdbcConnectorUtils.executeUpdate(connection, generateDropTableSql(tableName));
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
protected ResultSet getTables(Connection connection) throws SQLException {
final DatabaseMetaData metaData = connection.getMetaData();
String catalogName = connection.getCatalog();
diff --git a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/TableOperation.java b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/TableOperation.java
index e8a4fb36db..8cd5bb6850 100644
--- a/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/TableOperation.java
+++ b/catalogs/catalog-jdbc-common/src/main/java/com/datastrato/gravitino/catalog/jdbc/operation/TableOperation.java
@@ -61,8 +61,9 @@ public interface TableOperation {
/**
* @param databaseName The name of the database.
* @param tableName The name of the table.
+ * @return true if the table is successfully dropped; false if the table does not exist.
*/
- void drop(String databaseName, String tableName) throws NoSuchTableException;
+ boolean drop(String databaseName, String tableName);
/**
* @param databaseName The name of the database.
diff --git a/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/integration/test/TestJdbcAbstractIT.java b/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/integration/test/TestJdbcAbstractIT.java
index 31c6b2b799..4772dcd7c5 100644
--- a/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/integration/test/TestJdbcAbstractIT.java
+++ b/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/integration/test/TestJdbcAbstractIT.java
@@ -82,12 +82,15 @@ public abstract class TestJdbcAbstractIT {
protected static void testDropDatabase(String databaseName) {
List<String> databases;
- DATABASE_OPERATIONS.delete(databaseName, true);
+ Assertions.assertTrue(
+ DATABASE_OPERATIONS.delete(databaseName, true), "database should be dropped");
Assertions.assertThrows(
NoSuchSchemaException.class, () -> DATABASE_OPERATIONS.load(databaseName));
databases = DATABASE_OPERATIONS.listDatabases();
Assertions.assertFalse(databases.contains(databaseName));
+ Assertions.assertFalse(
+ DATABASE_OPERATIONS.delete(databaseName, true), "database should be non-existent");
}
protected static void assertionsTableInfo(
diff --git a/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/SqliteDatabaseOperations.java b/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/SqliteDatabaseOperations.java
index b8fd9ad9f0..57f11669d6 100644
--- a/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/SqliteDatabaseOperations.java
+++ b/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/SqliteDatabaseOperations.java
@@ -73,12 +73,12 @@ public class SqliteDatabaseOperations extends JdbcDatabaseOperations {
}
@Override
- public void delete(String databaseName, boolean cascade) throws NoSuchSchemaException {
- delete(databaseName);
+ public boolean delete(String databaseName, boolean cascade) throws NoSuchSchemaException {
+ return delete(databaseName);
}
- public void delete(String databaseName) {
- FileUtils.deleteQuietly(new File(dbPath + "/" + databaseName));
+ public boolean delete(String databaseName) {
+ return FileUtils.deleteQuietly(new File(dbPath + "/" + databaseName));
}
@Override
diff --git a/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/TestJdbcDatabaseOperations.java b/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/TestJdbcDatabaseOperations.java
index 2225548d6a..7dcc634ea9 100644
--- a/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/TestJdbcDatabaseOperations.java
+++ b/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/TestJdbcDatabaseOperations.java
@@ -91,11 +91,15 @@ public class TestJdbcDatabaseOperations {
Assertions.assertTrue(listDatabases.contains(database2));
// drop database
- JDBC_DATABASE_OPERATIONS.delete(database1);
+ Assertions.assertTrue(JDBC_DATABASE_OPERATIONS.delete(database1), "database should be dropped");
List<String> databases = JDBC_DATABASE_OPERATIONS.listDatabases();
Assertions.assertFalse(databases.contains(database1));
Assertions.assertNotNull(JDBC_DATABASE_OPERATIONS.load(database2));
- JDBC_DATABASE_OPERATIONS.delete(database2);
+ Assertions.assertTrue(JDBC_DATABASE_OPERATIONS.delete(database2), "database should be dropped");
Assertions.assertNull(JDBC_DATABASE_OPERATIONS.load(database2));
+
+ // drop non-existent database
+ Assertions.assertFalse(
+ JDBC_DATABASE_OPERATIONS.delete(database1), "database should be non-existent");
}
}
diff --git a/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/TestJdbcTableOperations.java b/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/TestJdbcTableOperations.java
index 213aa17f54..27fbc9c4a1 100644
--- a/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/TestJdbcTableOperations.java
+++ b/catalogs/catalog-jdbc-common/src/test/java/com/datastrato/gravitino/catalog/jdbc/operation/TestJdbcTableOperations.java
@@ -187,9 +187,14 @@ public class TestJdbcTableOperations {
() -> JDBC_TABLE_OPERATIONS.alterTable(DATABASE_NAME, newName, tableChange));
// delete table.
- JDBC_TABLE_OPERATIONS.drop(DATABASE_NAME, newName);
+ Assertions.assertTrue(
+ JDBC_TABLE_OPERATIONS.drop(DATABASE_NAME, newName), "table should be dropped");
allTables = JDBC_TABLE_OPERATIONS.listTables(DATABASE_NAME);
Assertions.assertEquals(0, allTables.size());
+
+ // delete non-existent table.
+ Assertions.assertFalse(
+ JDBC_TABLE_OPERATIONS.drop(DATABASE_NAME, newName), "table should be non-existent");
}
private static JdbcColumn[] generateRandomColumn(int minSize, int maxSize) {
diff --git a/catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/converter/DorisExceptionConverter.java b/catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/converter/DorisExceptionConverter.java
index 60bcf61b29..7b5758bb47 100644
--- a/catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/converter/DorisExceptionConverter.java
+++ b/catalogs/catalog-jdbc-doris/src/main/java/com/datastrato/gravitino/catalog/doris/converter/DorisExceptionConverter.java
@@ -25,6 +25,7 @@ public class DorisExceptionConverter extends JdbcExceptionConverter {
static final int CODE_TABLE_EXISTS = 1050;
static final int CODE_NO_SUCH_SCHEMA = 1049;
static final int CODE_DATABASE_NOT_EXISTS = 1008;
+ static final int CODE_UNKNOWN_DATABASE = 1049;
static final int CODE_NO_SUCH_TABLE = 1051;
static final int CODE_UNAUTHORIZED = 1045;
static final int CODE_NO_SUCH_COLUMN = 1054;
@@ -35,6 +36,16 @@ public class DorisExceptionConverter extends JdbcExceptionConverter {
private static final Pattern DATABASE_ALREADY_EXISTS_PATTERN =
Pattern.compile(DATABASE_ALREADY_EXISTS_PATTERN_STRING);
+ private static final String DATABASE_NOT_EXISTS_PATTERN_STRING =
+ ".*?detailMessage = Can't drop database '.*?'; database doesn't exist";
+ private static final Pattern DATABASE_NOT_EXISTS_PATTERN =
+ Pattern.compile(DATABASE_NOT_EXISTS_PATTERN_STRING);
+
+ private static final String UNKNOWN_DATABASE_PATTERN_STRING =
+ ".*?detailMessage = Unknown database '.*?'";
+ private static final Pattern UNKNOWN_DATABASE_PATTERN_PATTERN =
+ Pattern.compile(UNKNOWN_DATABASE_PATTERN_STRING);
+
private static final String TABLE_NOT_EXIST_PATTERN_STRING =
".*detailMessage = Unknown table '.*' in .*:.*";
@@ -55,6 +66,7 @@ public class DorisExceptionConverter extends JdbcExceptionConverter {
case CODE_TABLE_EXISTS:
return new TableAlreadyExistsException(se, se.getMessage());
case CODE_DATABASE_NOT_EXISTS:
+ case CODE_UNKNOWN_DATABASE:
return new NoSuchSchemaException(se, se.getMessage());
case CODE_NO_SUCH_TABLE:
return new NoSuchTableException(se, se.getMessage());
@@ -76,6 +88,14 @@ public class DorisExceptionConverter extends JdbcExceptionConverter {
return CODE_DATABASE_EXISTS;
}
+ if (DATABASE_NOT_EXISTS_PATTERN.matcher(message).matches()) {
+ return CODE_DATABASE_NOT_EXISTS;
+ }
+
+ if (UNKNOWN_DATABASE_PATTERN_PATTERN.matcher(message).matches()) {
+ return CODE_UNKNOWN_DATABASE;
+ }
+
if (TABLE_NOT_EXIST_PATTERN.matcher(message).matches()) {
return CODE_NO_SUCH_TABLE;
}
diff --git a/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/converter/TestDorisExceptionConverter.java b/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/converter/TestDorisExceptionConverter.java
index 88d484d35b..3ae51acdb8 100644
--- a/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/converter/TestDorisExceptionConverter.java
+++ b/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/converter/TestDorisExceptionConverter.java
@@ -16,6 +16,17 @@ public class TestDorisExceptionConverter {
DorisExceptionConverter.CODE_DATABASE_EXISTS,
DorisExceptionConverter.getErrorCodeFromMessage(msg));
+ msg =
+ "errCode = 2, detailMessage = Can't drop database 'default_cluster:test_schema'; database doesn't exist";
+ Assertions.assertEquals(
+ DorisExceptionConverter.CODE_DATABASE_NOT_EXISTS,
+ DorisExceptionConverter.getErrorCodeFromMessage(msg));
+
+ msg = "errCode = 2, detailMessage = Unknown database 'default_cluster:no-exits'";
+ Assertions.assertEquals(
+ DorisExceptionConverter.CODE_UNKNOWN_DATABASE,
+ DorisExceptionConverter.getErrorCodeFromMessage(msg));
+
msg =
"errCode = 2, detailMessage = Unknown table 'table_name' in default_cluster:database_name";
Assertions.assertEquals(
diff --git a/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/integration/test/CatalogDorisIT.java b/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/integration/test/CatalogDorisIT.java
index 5751ae6d81..12f4a5649c 100644
--- a/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/integration/test/CatalogDorisIT.java
+++ b/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/integration/test/CatalogDorisIT.java
@@ -8,7 +8,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import com.datastrato.gravitino.Catalog;
import com.datastrato.gravitino.NameIdentifier;
-import com.datastrato.gravitino.Namespace;
import com.datastrato.gravitino.Schema;
import com.datastrato.gravitino.SupportsSchemas;
import com.datastrato.gravitino.catalog.jdbc.config.JdbcConfig;
@@ -109,6 +108,7 @@ public class CatalogDorisIT extends AbstractIT {
@AfterAll
public void stop() {
clearTableAndSchema();
+ metalake.dropCatalog(catalogName);
AbstractIT.client.dropMetalake(metalakeName);
}
@@ -119,11 +119,6 @@ public class CatalogDorisIT extends AbstractIT {
}
private void clearTableAndSchema() {
- NameIdentifier[] nameIdentifiers =
- catalog.asTableCatalog().listTables(Namespace.of(metalakeName, catalogName, schemaName));
- for (NameIdentifier nameIdentifier : nameIdentifiers) {
- catalog.asTableCatalog().dropTable(nameIdentifier);
- }
catalog.asSchemas().dropSchema(schemaName, true);
}
@@ -262,7 +257,10 @@ public class CatalogDorisIT extends AbstractIT {
null);
// Try to drop a database, and cascade equals to false, it should not be allowed.
- Assertions.assertFalse(catalog.asSchemas().dropSchema(schemaName, false));
+ Throwable excep =
+ Assertions.assertThrows(
+ RuntimeException.class, () -> catalog.asSchemas().dropSchema(schemaName, false));
+ Assertions.assertTrue(excep.getMessage().contains("the value of cascade should be true."));
// Check the database still exists
catalog.asSchemas().loadSchema(schemaName);
diff --git a/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/integration/test/DorisTableOperationsIT.java b/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/integration/test/DorisTableOperationsIT.java
index 1b6967f5c7..89c04124f9 100644
--- a/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/integration/test/DorisTableOperationsIT.java
+++ b/catalogs/catalog-jdbc-doris/src/test/java/com/datastrato/gravitino/catalog/doris/integration/test/DorisTableOperationsIT.java
@@ -6,7 +6,6 @@ package com.datastrato.gravitino.catalog.doris.integration.test;
import com.datastrato.gravitino.catalog.jdbc.JdbcColumn;
import com.datastrato.gravitino.catalog.jdbc.JdbcTable;
-import com.datastrato.gravitino.exceptions.NoSuchTableException;
import com.datastrato.gravitino.integration.test.util.GravitinoITUtils;
import com.datastrato.gravitino.rel.TableChange;
import com.datastrato.gravitino.rel.expressions.NamedReference;
@@ -107,13 +106,13 @@ public class DorisTableOperationsIT extends TestDorisAbstractIT {
Assertions.assertDoesNotThrow(() -> TABLE_OPERATIONS.rename(databaseName, tableName, newName));
Assertions.assertDoesNotThrow(() -> TABLE_OPERATIONS.load(databaseName, newName));
- Assertions.assertDoesNotThrow(() -> TABLE_OPERATIONS.drop(databaseName, newName));
+ Assertions.assertTrue(TABLE_OPERATIONS.drop(databaseName, newName), "table should be dropped");
listTables = TABLE_OPERATIONS.listTables(databaseName);
Assertions.assertFalse(listTables.contains(newName));
- Assertions.assertThrows(
- NoSuchTableException.class, () -> TABLE_OPERATIONS.drop(databaseName, newName));
+ Assertions.assertFalse(
+ TABLE_OPERATIONS.drop(databaseName, newName), "table should be non-existent");
}
@Test
diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/AuditCatalogMysqlIT.java b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/AuditCatalogMysqlIT.java
index d345997546..51b8d531d7 100644
--- a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/AuditCatalogMysqlIT.java
+++ b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/AuditCatalogMysqlIT.java
@@ -75,9 +75,9 @@ public class AuditCatalogMysqlIT extends AbstractIT {
@AfterAll
public static void stopIntegrationTest() throws IOException, InterruptedException {
- AbstractIT.stopIntegrationTest();
client.dropMetalake(metalakeName);
mysqlService.close();
+ AbstractIT.stopIntegrationTest();
}
@Test
@@ -92,6 +92,8 @@ public class AuditCatalogMysqlIT extends AbstractIT {
catalog = metalake.alterCatalog(catalogName, CatalogChange.setProperty("key1", "value1"));
Assertions.assertEquals(expectUser, catalog.auditInfo().creator());
Assertions.assertEquals(expectUser, catalog.auditInfo().lastModifier());
+
+ metalake.dropCatalog(catalogName);
}
@Test
@@ -103,6 +105,9 @@ public class AuditCatalogMysqlIT extends AbstractIT {
Schema schema = catalog.asSchemas().createSchema(schemaName, null, prop);
Assertions.assertEquals(expectUser, schema.auditInfo().creator());
Assertions.assertNull(schema.auditInfo().lastModifier());
+
+ catalog.asSchemas().dropSchema(schemaName, true);
+ metalake.dropCatalog(catalogName);
}
@Test
@@ -134,6 +139,12 @@ public class AuditCatalogMysqlIT extends AbstractIT {
TableChange.addColumn(new String[] {"col_4"}, Types.StringType.get()));
Assertions.assertEquals(expectUser, table.auditInfo().creator());
Assertions.assertEquals(expectUser, table.auditInfo().lastModifier());
+
+ catalog
+ .asTableCatalog()
+ .dropTable(NameIdentifier.of(metalakeName, catalogName, schemaName, tableName));
+ catalog.asSchemas().dropSchema(schemaName, true);
+ metalake.dropCatalog(catalogName);
}
private static Catalog createCatalog(String catalogName) throws SQLException {
diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
index 425e33db93..c092aa26b2 100644
--- a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
+++ b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
@@ -138,6 +138,7 @@ public class CatalogMysqlIT extends AbstractIT {
@AfterAll
public void stop() {
clearTableAndSchema();
+ metalake.dropCatalog(catalogName);
client.dropMetalake(metalakeName);
mysqlService.close();
}
@@ -856,7 +857,11 @@ public class CatalogMysqlIT extends AbstractIT {
// Try to drop a database, and cascade equals to false, it should not be
// allowed.
- catalog.asSchemas().dropSchema(schemaName, false);
+ Throwable excep =
+ Assertions.assertThrows(
+ RuntimeException.class, () -> catalog.asSchemas().dropSchema(schemaName, false));
+ Assertions.assertTrue(excep.getMessage().contains("the value of cascade should be true."));
+
// Check the database still exists
catalog.asSchemas().loadSchema(schemaName);
diff --git a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/MysqlTableOperationsIT.java b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/MysqlTableOperationsIT.java
index bd0e4b04fd..dd780a4c9a 100644
--- a/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/MysqlTableOperationsIT.java
+++ b/catalogs/catalog-jdbc-mysql/src/test/java/com/datastrato/gravitino/catalog/mysql/integration/test/MysqlTableOperationsIT.java
@@ -10,7 +10,6 @@ import static com.datastrato.gravitino.catalog.mysql.MysqlTablePropertiesMetadat
import com.datastrato.gravitino.catalog.jdbc.JdbcColumn;
import com.datastrato.gravitino.catalog.jdbc.JdbcTable;
import com.datastrato.gravitino.exceptions.GravitinoRuntimeException;
-import com.datastrato.gravitino.exceptions.NoSuchTableException;
import com.datastrato.gravitino.rel.Column;
import com.datastrato.gravitino.rel.TableChange;
import com.datastrato.gravitino.rel.expressions.distributions.Distributions;
@@ -171,9 +170,10 @@ public class MysqlTableOperationsIT extends TestMysqlAbstractIT {
TEST_DB_NAME.toString(),
newName,
TableChange.deleteColumn(new String[] {newColumn.name()}, true));
- Assertions.assertDoesNotThrow(() -> TABLE_OPERATIONS.drop(TEST_DB_NAME.toString(), newName));
- Assertions.assertThrows(
- NoSuchTableException.class, () -> TABLE_OPERATIONS.drop(TEST_DB_NAME.toString(), newName));
+ Assertions.assertTrue(
+ TABLE_OPERATIONS.drop(TEST_DB_NAME.toString(), newName), "table should be dropped");
+ Assertions.assertFalse(
+ TABLE_OPERATIONS.drop(TEST_DB_NAME.toString(), newName), "table should be non-existent");
}
@Test
diff --git a/catalogs/catalog-jdbc-postgresql/src/test/java/com/datastrato/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java b/catalogs/catalog-jdbc-postgresql/src/test/java/com/datastrato/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java
index ca8d771427..e0a8ddb024 100644
--- a/catalogs/catalog-jdbc-postgresql/src/test/java/com/datastrato/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java
+++ b/catalogs/catalog-jdbc-postgresql/src/test/java/com/datastrato/gravitino/catalog/postgresql/integration/test/CatalogPostgreSqlIT.java
@@ -119,6 +119,11 @@ public class CatalogPostgreSqlIT extends AbstractIT {
@AfterAll
public void stop() {
clearTableAndSchema();
+ NameIdentifier[] schemaIdentifiers = catalog.asSchemas().listSchemas();
+ for (NameIdentifier nameIdentifier : schemaIdentifiers) {
+ catalog.asSchemas().dropSchema(nameIdentifier.name(), true);
+ }
+ metalake.dropCatalog(catalogName);
client.dropMetalake(metalakeName);
postgreSqlService.close();
}
@@ -337,7 +342,7 @@ public class CatalogPostgreSqlIT extends AbstractIT {
schemaMap =
Arrays.stream(nameIdentifiers).collect(Collectors.toMap(NameIdentifier::name, v -> v));
Assertions.assertFalse(schemaMap.containsKey(testSchemaName));
- Assertions.assertFalse(schemas.dropSchema("no-exits", false));
+ Assertions.assertFalse(schemas.dropSchema("no_exits", false));
TableCatalog tableCatalog = catalog.asTableCatalog();
// create failed check.
diff --git a/catalogs/catalog-jdbc-postgresql/src/test/java/com/datastrato/gravitino/catalog/postgresql/integration/test/PostgreSqlTableOperationsIT.java b/catalogs/catalog-jdbc-postgresql/src/test/java/com/datastrato/gravitino/catalog/postgresql/integration/test/PostgreSqlTableOperationsIT.java
index 65e0e89002..7290b7b794 100644
--- a/catalogs/catalog-jdbc-postgresql/src/test/java/com/datastrato/gravitino/catalog/postgresql/integration/test/PostgreSqlTableOperationsIT.java
+++ b/catalogs/catalog-jdbc-postgresql/src/test/java/com/datastrato/gravitino/catalog/postgresql/integration/test/PostgreSqlTableOperationsIT.java
@@ -246,8 +246,7 @@ public class PostgreSqlTableOperationsIT extends TestPostgreSqlAbstractIT {
newName,
TableChange.deleteColumn(new String[] {newColumn.name()}, true)));
Assertions.assertDoesNotThrow(() -> TABLE_OPERATIONS.drop(TEST_DB_NAME, newName));
- Assertions.assertThrows(
- NoSuchTableException.class, () -> TABLE_OPERATIONS.drop(TEST_DB_NAME, newName));
+ Assertions.assertFalse(TABLE_OPERATIONS.drop(TEST_DB_NAME, newName));
}
@Test
diff --git a/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java b/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java
index 3aec55d881..fda4b9d152 100644
--- a/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java
+++ b/catalogs/catalog-kafka/src/test/java/com/datastrato/gravitino/catalog/kafka/integration/test/CatalogKafkaIT.java
@@ -99,6 +99,18 @@ public class CatalogKafkaIT extends AbstractIT {
@AfterAll
public static void shutdown() {
+ Catalog catalog = metalake.loadCatalog(CATALOG_NAME);
+ Arrays.stream(catalog.asSchemas().listSchemas())
+ .filter(ident -> !ident.name().equals("default"))
+ .forEach(
+ (ident -> {
+ catalog.asSchemas().dropSchema(ident.name(), true);
+ }));
+ Arrays.stream(metalake.listCatalogs())
+ .forEach(
+ (ident -> {
+ metalake.dropCatalog(ident.name());
+ }));
client.dropMetalake(METALAKE_NAME);
if (adminClient != null) {
adminClient.close();
@@ -144,6 +156,7 @@ public class CatalogKafkaIT extends AbstractIT {
Assertions.assertThrows(
NoSuchCatalogException.class, () -> metalake.loadCatalog(catalogName));
Assertions.assertTrue(exception.getMessage().contains(catalogName));
+ Assertions.assertFalse(metalake.dropCatalog(catalogName), "catalog should be non-existent");
// assert topic exists in Kafka after catalog dropped
Assertions.assertFalse(adminClient.listTopics().names().get().isEmpty());
}
@@ -226,8 +239,11 @@ public class CatalogKafkaIT extends AbstractIT {
Assertions.assertTrue(exception.getMessage().contains("Cannot alter the default schema"));
// test drop default schema
- boolean dropped = catalog.asSchemas().dropSchema(DEFAULT_SCHEMA_NAME, true);
- Assertions.assertFalse(dropped);
+ Throwable excep =
+ Assertions.assertThrows(
+ RuntimeException.class,
+ () -> catalog.asSchemas().dropSchema(DEFAULT_SCHEMA_NAME, true));
+ Assertions.assertTrue(excep.getMessage().contains("Cannot drop the default schema"));
}
@Test
diff --git a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
index 1d52b57868..53840adcda 100644
--- a/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
+++ b/catalogs/catalog-lakehouse-iceberg/src/main/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/IcebergCatalogOperations.java
@@ -284,7 +284,7 @@ public class IcebergCatalogOperations implements CatalogOperations, SupportsSche
*
* @param ident The identifier of the schema to drop.
* @param cascade If set to true, drops all the tables in the schema as well.
- * @return true if the schema was dropped successfully, false otherwise.
+ * @return true if the schema was dropped successfully, false if the schema does not exist.
* @throws NonEmptySchemaException If the schema is not empty and 'cascade' is set to false.
*/
@Override
diff --git a/catalogs/catalog-lakehouse-iceberg/src/test/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/integration/test/CatalogIcebergBaseIT.java b/catalogs/catalog-lakehouse-iceberg/src/test/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/integration/test/CatalogIcebergBaseIT.java
index bcadbe1758..a2d0979ec7 100644
--- a/catalogs/catalog-lakehouse-iceberg/src/test/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/integration/test/CatalogIcebergBaseIT.java
+++ b/catalogs/catalog-lakehouse-iceberg/src/test/java/com/datastrato/gravitino/catalog/lakehouse/iceberg/integration/test/CatalogIcebergBaseIT.java
@@ -120,6 +120,7 @@ public abstract class CatalogIcebergBaseIT extends AbstractIT {
@AfterAll
public void stop() throws Exception {
clearTableAndSchema();
+ metalake.dropCatalog(catalogName);
client.dropMetalake(metalakeName);
spark.close();
AbstractIT.stopIntegrationTest();
@@ -159,12 +160,14 @@ public abstract class CatalogIcebergBaseIT extends AbstractIT {
}
private void clearTableAndSchema() {
- NameIdentifier[] nameIdentifiers =
- catalog.asTableCatalog().listTables(Namespace.of(metalakeName, catalogName, schemaName));
- for (NameIdentifier nameIdentifier : nameIdentifiers) {
- catalog.asTableCatalog().dropTable(nameIdentifier);
+ if (catalog.asSchemas().schemaExists(schemaName)) {
+ NameIdentifier[] nameIdentifiers =
+ catalog.asTableCatalog().listTables(Namespace.of(metalakeName, catalogName, schemaName));
+ for (NameIdentifier nameIdentifier : nameIdentifiers) {
+ catalog.asTableCatalog().dropTable(nameIdentifier);
+ }
+ catalog.asSchemas().dropSchema(schemaName, false);
}
- catalog.asSchemas().dropSchema(schemaName, false);
}
private void createMetalake() {
@@ -324,7 +327,12 @@ public abstract class CatalogIcebergBaseIT extends AbstractIT {
Distributions.NONE,
null));
// drop schema failed check.
- Assertions.assertFalse(schemas.dropSchema(schemaIdent.name(), true));
+ Throwable excep =
+ Assertions.assertThrows(
+ IllegalArgumentException.class, () -> schemas.dropSchema(schemaIdent.name(), true));
+ Assertions.assertTrue(
+ excep.getMessage().contains("Iceberg does not support cascading delete operations."));
+
Assertions.assertFalse(schemas.dropSchema(schemaIdent.name(), false));
Assertions.assertFalse(tableCatalog.dropTable(table));
icebergNamespaces =
@@ -731,6 +739,7 @@ public abstract class CatalogIcebergBaseIT extends AbstractIT {
Table delColTable = catalog.asTableCatalog().loadTable(tableIdentifier);
Assertions.assertEquals(1, delColTable.columns().length);
Assertions.assertEquals(col1.name(), delColTable.columns()[0].name());
+ catalog.asTableCatalog().dropTable(tableIdentifier);
}
@Test
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/BaseSchemaCatalog.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/BaseSchemaCatalog.java
index 66ec720e79..16d372b4b2 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/BaseSchemaCatalog.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/BaseSchemaCatalog.java
@@ -28,8 +28,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* BaseSchemaCatalog is the base abstract class for all the catalog with schema. It provides the
@@ -37,8 +35,6 @@ import org.slf4j.LoggerFactory;
* create, load, alter and drop a schema with specified identifier.
*/
abstract class BaseSchemaCatalog extends CatalogDTO implements Catalog, SupportsSchemas {
- private static final Logger LOG = LoggerFactory.getLogger(BaseSchemaCatalog.class);
-
/** The REST client to send the requests. */
protected final RESTClient restClient;
/** The namespace of current catalog, which is the metalake name. */
@@ -180,24 +176,15 @@ abstract class BaseSchemaCatalog extends CatalogDTO implements Catalog, Supports
*/
@Override
public boolean dropSchema(String schemaName, boolean cascade) throws NonEmptySchemaException {
-
- try {
- DropResponse resp =
- restClient.delete(
- formatSchemaRequestPath(schemaNamespace) + "/" + RESTUtils.encodeString(schemaName),
- Collections.singletonMap("cascade", String.valueOf(cascade)),
- DropResponse.class,
- Collections.emptyMap(),
- ErrorHandlers.schemaErrorHandler());
- resp.validate();
- return resp.dropped();
-
- } catch (NonEmptySchemaException e) {
- throw e;
- } catch (Exception e) {
- LOG.warn("Failed to drop schema {}", schemaName, e);
- return false;
- }
+ DropResponse resp =
+ restClient.delete(
+ formatSchemaRequestPath(schemaNamespace) + "/" + RESTUtils.encodeString(schemaName),
+ Collections.singletonMap("cascade", String.valueOf(cascade)),
+ DropResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.schemaErrorHandler());
+ resp.validate();
+ return resp.dropped();
}
static String formatSchemaRequestPath(Namespace ns) {
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java
index 1ba9965074..aaff7ee9a5 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoAdminClient.java
@@ -42,8 +42,6 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Gravitino Client for the administrator to interact with the Gravitino API, allowing the client to
@@ -52,8 +50,6 @@ import org.slf4j.LoggerFactory;
* <p>Normal users should use {@link GravitinoClient} to connect with the Gravitino server.
*/
public class GravitinoAdminClient extends GravitinoClientBase implements SupportsMetalakes {
-
- private static final Logger LOG = LoggerFactory.getLogger(GravitinoAdminClient.class);
private static final String API_METALAKES_USERS_PATH = "api/metalakes/%s/users/%s";
private static final String API_METALAKES_GROUPS_PATH = "api/metalakes/%s/groups/%s";
private static final String API_METALAKES_ROLES_PATH = "api/metalakes/%s/roles/%s";
@@ -165,25 +161,19 @@ public class GravitinoAdminClient extends GravitinoClientBase implements Support
* Drops a specific Metalake using the Gravitino API.
*
* @param name The name of the Metalake to be dropped.
- * @return True if the Metalake was successfully dropped, false otherwise.
+ * @return True if the Metalake was successfully dropped, false if the Metalake does not exist.
*/
@Override
public boolean dropMetalake(String name) {
checkMetalakeName(name);
- try {
- DropResponse resp =
- restClient.delete(
- API_METALAKES_IDENTIFIER_PATH + name,
- DropResponse.class,
- Collections.emptyMap(),
- ErrorHandlers.metalakeErrorHandler());
- resp.validate();
- return resp.dropped();
-
- } catch (Exception e) {
- LOG.warn("Failed to drop metadata {}", name, e);
- return false;
- }
+ DropResponse resp =
+ restClient.delete(
+ API_METALAKES_IDENTIFIER_PATH + name,
+ DropResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.metalakeErrorHandler());
+ resp.validate();
+ return resp.dropped();
}
/**
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetalake.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetalake.java
index f207d4d991..5b8cd07023 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetalake.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/GravitinoMetalake.java
@@ -28,8 +28,6 @@ import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* Gravitino Metalake is the top-level metadata repository for users. It contains a list of catalogs
@@ -37,9 +35,6 @@ import org.slf4j.LoggerFactory;
* alter and drop a catalog with specified identifier.
*/
public class GravitinoMetalake extends MetalakeDTO implements SupportsCatalogs {
-
- private static final Logger LOG = LoggerFactory.getLogger(GravitinoMetalake.class);
-
private static final String API_METALAKES_CATALOGS_PATH = "api/metalakes/%s/catalogs/%s";
private final RESTClient restClient;
@@ -192,25 +187,19 @@ public class GravitinoMetalake extends MetalakeDTO implements SupportsCatalogs {
* Drop the catalog with specified identifier.
*
* @param catalogName the name of the catalog.
- * @return true if the catalog is dropped successfully, false otherwise.
+ * @return true if the catalog is dropped successfully, false if the catalog does not exist.
*/
@Override
public boolean dropCatalog(String catalogName) {
- try {
- DropResponse resp =
- restClient.delete(
- String.format(API_METALAKES_CATALOGS_PATH, this.name(), catalogName),
- DropResponse.class,
- Collections.emptyMap(),
- ErrorHandlers.catalogErrorHandler());
- resp.validate();
- return resp.dropped();
-
- } catch (Exception e) {
- LOG.warn("Failed to drop catalog {}", catalogName, e);
- return false;
- }
+ DropResponse resp =
+ restClient.delete(
+ String.format(API_METALAKES_CATALOGS_PATH, this.name(), catalogName),
+ DropResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.catalogErrorHandler());
+ resp.validate();
+ return resp.dropped();
}
static class Builder extends MetalakeDTO.Builder<Builder> {
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java
index 2cd54fab6a..02080961e4 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalCatalog.java
@@ -199,28 +199,20 @@ public class RelationalCatalog extends BaseSchemaCatalog implements TableCatalog
* Drop the table with specified identifier.
*
* @param ident The identifier of the table.
- * @return true if the table is dropped successfully, false otherwise.
+ * @return true if the table is dropped successfully, false if the table does not exist.
*/
@Override
public boolean dropTable(NameIdentifier ident) {
NameIdentifier.checkTable(ident);
- try {
- DropResponse resp =
- restClient.delete(
- formatTableRequestPath(ident.namespace())
- + "/"
- + RESTUtils.encodeString(ident.name()),
- DropResponse.class,
- Collections.emptyMap(),
- ErrorHandlers.tableErrorHandler());
- resp.validate();
- return resp.dropped();
-
- } catch (Exception e) {
- LOG.warn("Failed to drop table {}", ident, e);
- return false;
- }
+ DropResponse resp =
+ restClient.delete(
+ formatTableRequestPath(ident.namespace()) + "/" + RESTUtils.encodeString(ident.name()),
+ DropResponse.class,
+ Collections.emptyMap(),
+ ErrorHandlers.tableErrorHandler());
+ resp.validate();
+ return resp.dropped();
}
/**
diff --git a/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalTable.java b/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalTable.java
index a551558d0e..26628374b4 100644
--- a/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalTable.java
+++ b/clients/client-java/src/main/java/com/datastrato/gravitino/client/RelationalTable.java
@@ -222,7 +222,7 @@ public class RelationalTable implements Table, SupportsPartitions {
* Drops the partition with the given name.
*
* @param partitionName The name of the partition.
- * @return true if the partition is dropped, false otherwise.
+ * @return true if the partition is dropped, false if the partition does not exist.
*/
@Override
public boolean dropPartition(String partitionName) {
diff --git a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoClient.java b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoClient.java
index 7d150addba..98123eb338 100644
--- a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoClient.java
+++ b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoClient.java
@@ -223,17 +223,19 @@ public class TestGravitinoClient extends TestBase {
public void testDropMetalake() throws JsonProcessingException {
DropResponse resp = new DropResponse(true);
buildMockResource(Method.DELETE, "/api/metalakes/mock", null, resp, HttpStatus.SC_OK);
- Assertions.assertTrue(client.dropMetalake("mock"));
+ Assertions.assertTrue(client.dropMetalake("mock"), "metalake should be dropped");
DropResponse resp1 = new DropResponse(false);
buildMockResource(Method.DELETE, "/api/metalakes/mock", null, resp1, HttpStatus.SC_OK);
- Assertions.assertFalse(client.dropMetalake("mock"));
+ Assertions.assertFalse(client.dropMetalake("mock"), "metalake should be non-existent");
// Test return internal error
ErrorResponse errorResp = ErrorResponse.internalError("mock error");
buildMockResource(
Method.DELETE, "/api/metalakes/mock", null, errorResp, HttpStatus.SC_INTERNAL_SERVER_ERROR);
- Assertions.assertFalse(client.dropMetalake("mock"));
+ Throwable excep =
+ Assertions.assertThrows(RuntimeException.class, () -> client.dropMetalake("mock"));
+ Assertions.assertTrue(excep.getMessage().contains("mock error"));
// Test illegal metalake name identifier
String badName = "mock.mock";
diff --git a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoMetalake.java b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoMetalake.java
index 7cdf69a420..1969b8fff0 100644
--- a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoMetalake.java
+++ b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestGravitinoMetalake.java
@@ -367,13 +367,13 @@ public class TestGravitinoMetalake extends TestBase {
DropResponse resp = new DropResponse(true);
buildMockResource(Method.DELETE, path, null, resp, HttpStatus.SC_OK);
boolean dropped = gravitinoClient.dropCatalog(catalogName);
- Assertions.assertTrue(dropped);
+ Assertions.assertTrue(dropped, "catalog should be dropped");
// Test return false
DropResponse resp1 = new DropResponse(false);
buildMockResource(Method.DELETE, path, null, resp1, HttpStatus.SC_OK);
boolean dropped1 = gravitinoClient.dropCatalog(catalogName);
- Assertions.assertFalse(dropped1);
+ Assertions.assertFalse(dropped1, "catalog should be non-existent");
}
static GravitinoMetalake createMetalake(GravitinoAdminClient client, String metalakeName)
diff --git a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRelationalCatalog.java b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRelationalCatalog.java
index 83705ba5c7..7997870dcd 100644
--- a/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRelationalCatalog.java
+++ b/clients/client-java/src/test/java/com/datastrato/gravitino/client/TestRelationalCatalog.java
@@ -1073,7 +1073,10 @@ public class TestRelationalCatalog extends TestBase {
ErrorResponse errorResp = ErrorResponse.internalError("internal error");
buildMockResource(Method.DELETE, tablePath, null, errorResp, SC_INTERNAL_SERVER_ERROR);
- Assertions.assertFalse(catalog.asTableCatalog().dropTable(tableId));
+ Throwable excep =
+ Assertions.assertThrows(
+ RuntimeException.class, () -> catalog.asTableCatalog().dropTable(tableId));
+ Assertions.assertTrue(excep.getMessage().contains("internal error"));
}
@Test
diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/SupportsCatalogs.java b/core/src/main/java/com/datastrato/gravitino/catalog/SupportsCatalogs.java
index c1ce8cb586..2e68d1fae8 100644
--- a/core/src/main/java/com/datastrato/gravitino/catalog/SupportsCatalogs.java
+++ b/core/src/main/java/com/datastrato/gravitino/catalog/SupportsCatalogs.java
@@ -104,7 +104,7 @@ public interface SupportsCatalogs {
* Drop a catalog with specified identifier.
*
* @param ident the identifier of the catalog.
- * @return True if the catalog was dropped, false otherwise.
+ * @return True if the catalog was dropped, false if the catalog does not exist.
*/
boolean dropCatalog(NameIdentifier ident);
}
diff --git a/core/src/main/java/com/datastrato/gravitino/metalake/SupportsMetalakes.java b/core/src/main/java/com/datastrato/gravitino/metalake/SupportsMetalakes.java
index 664f60e3f0..43b0b1eb11 100644
--- a/core/src/main/java/com/datastrato/gravitino/metalake/SupportsMetalakes.java
+++ b/core/src/main/java/com/datastrato/gravitino/metalake/SupportsMetalakes.java
@@ -78,7 +78,7 @@ public interface SupportsMetalakes {
* Drop a metalake with specified identifier.
*
* @param ident The identifier of the metalake.
- * @return True if the metalake was dropped, false otherwise.
+ * @return True if the metalake was dropped, false if the metalake does not exist.
*/
boolean dropMetalake(NameIdentifier ident);
}
diff --git a/core/src/test/java/com/datastrato/gravitino/catalog/TestFilesetOperationDispatcher.java b/core/src/test/java/com/datastrato/gravitino/catalog/TestFilesetOperationDispatcher.java
index 068bdeb9ba..a29df9a276 100644
--- a/core/src/test/java/com/datastrato/gravitino/catalog/TestFilesetOperationDispatcher.java
+++ b/core/src/test/java/com/datastrato/gravitino/catalog/TestFilesetOperationDispatcher.java
@@ -141,5 +141,6 @@ public class TestFilesetOperationDispatcher extends TestOperationDispatcher {
boolean dropped = filesetOperationDispatcher.dropFileset(filesetIdent1);
Assertions.assertTrue(dropped);
+ Assertions.assertFalse(filesetOperationDispatcher.dropFileset(filesetIdent1));
}
}
diff --git a/core/src/test/java/com/datastrato/gravitino/catalog/TestSchemaOperationDispatcher.java b/core/src/test/java/com/datastrato/gravitino/catalog/TestSchemaOperationDispatcher.java
index adb8fc6c3d..c04b8e1a72 100644
--- a/core/src/test/java/com/datastrato/gravitino/catalog/TestSchemaOperationDispatcher.java
+++ b/core/src/test/java/com/datastrato/gravitino/catalog/TestSchemaOperationDispatcher.java
@@ -189,6 +189,7 @@ public class TestSchemaOperationDispatcher extends TestOperationDispatcher {
boolean dropped = dispatcher.dropSchema(schemaIdent, false);
Assertions.assertTrue(dropped);
+ Assertions.assertFalse(dispatcher.dropSchema(schemaIdent, false));
// Test if entity store is failed to drop the schema entity
dispatcher.createSchema(schemaIdent, "comment", props);
diff --git a/core/src/test/java/com/datastrato/gravitino/catalog/TestTableOperationDispatcher.java b/core/src/test/java/com/datastrato/gravitino/catalog/TestTableOperationDispatcher.java
index d7cc7236e5..83cee60523 100644
--- a/core/src/test/java/com/datastrato/gravitino/catalog/TestTableOperationDispatcher.java
+++ b/core/src/test/java/com/datastrato/gravitino/catalog/TestTableOperationDispatcher.java
@@ -265,6 +265,7 @@ public class TestTableOperationDispatcher extends TestOperationDispatcher {
boolean dropped = tableOperationDispatcher.dropTable(tableIdent);
Assertions.assertTrue(dropped);
+ Assertions.assertFalse(tableOperationDispatcher.dropTable(tableIdent));
// Test if the entity store is failed to drop the table entity
tableOperationDispatcher.createTable(tableIdent, columns, "comment", props, new Transform[0]);
diff --git a/core/src/test/java/com/datastrato/gravitino/catalog/TestTopicOperationDispatcher.java b/core/src/test/java/com/datastrato/gravitino/catalog/TestTopicOperationDispatcher.java
index 7aeb39ec1e..fd06db7614 100644
--- a/core/src/test/java/com/datastrato/gravitino/catalog/TestTopicOperationDispatcher.java
+++ b/core/src/test/java/com/datastrato/gravitino/catalog/TestTopicOperationDispatcher.java
@@ -193,6 +193,7 @@ public class TestTopicOperationDispatcher extends TestOperationDispatcher {
boolean dropped = topicOperationDispatcher.dropTopic(topicIdent);
Assertions.assertTrue(dropped);
+ Assertions.assertFalse(topicOperationDispatcher.dropTopic(topicIdent));
// Test if the entity store is failed to drop the topic entity
topicOperationDispatcher.createTopic(topicIdent, "comment", null, props);
diff --git a/core/src/test/java/com/datastrato/gravitino/metalake/TestMetalakeManager.java b/core/src/test/java/com/datastrato/gravitino/metalake/TestMetalakeManager.java
index ad86b4709f..dbfebfc1df 100644
--- a/core/src/test/java/com/datastrato/gravitino/metalake/TestMetalakeManager.java
+++ b/core/src/test/java/com/datastrato/gravitino/metalake/TestMetalakeManager.java
@@ -160,12 +160,12 @@ public class TestMetalakeManager {
testProperties(props, metalake.properties());
boolean dropped = metalakeManager.dropMetalake(ident);
- Assertions.assertTrue(dropped);
+ Assertions.assertTrue(dropped, "metalake should be dropped");
// Test with NoSuchMetalakeException
NameIdentifier ident1 = NameIdentifier.of("test42");
boolean dropped1 = metalakeManager.dropMetalake(ident1);
- Assertions.assertFalse(dropped1);
+ Assertions.assertFalse(dropped1, "metalake should be non-existent");
}
private void testProperties(Map<String, String> expectedProps, Map<String, String> testProps) {
diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/AuditIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/AuditIT.java
index d99d2d154e..298d0c1a8c 100644
--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/AuditIT.java
+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/AuditIT.java
@@ -46,6 +46,7 @@ public class AuditIT extends AbstractIT {
metaLake = client.alterMetalake(metalakeAuditName, changes);
Assertions.assertEquals(expectUser, metaLake.auditInfo().creator());
Assertions.assertEquals(expectUser, metaLake.auditInfo().lastModifier());
- client.dropMetalake(newName);
+ Assertions.assertTrue(client.dropMetalake(newName), "metaLake should be dropped");
+ Assertions.assertFalse(client.dropMetalake(newName), "metalake should be non-existent");
}
}
diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/CatalogIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/CatalogIT.java
index e11f9252ef..b7508c5dbe 100644
--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/CatalogIT.java
+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/CatalogIT.java
@@ -89,6 +89,23 @@ public class CatalogIT extends AbstractIT {
metalake.dropCatalog(catalogName);
}
+ @Test
+ public void testDropCatalog() {
+ String catalogName = GravitinoITUtils.genRandomName("catalog");
+ Assertions.assertFalse(metalake.catalogExists(catalogName));
+
+ Map<String, String> properties = Maps.newHashMap();
+ properties.put("metastore.uris", hmsUri);
+ Catalog catalog =
+ metalake.createCatalog(
+ catalogName, Catalog.Type.RELATIONAL, "hive", "catalog comment", properties);
+ Assertions.assertTrue(metalake.catalogExists(catalogName));
+ Assertions.assertEquals(catalogName, catalog.name());
+
+ Assertions.assertTrue(metalake.dropCatalog(catalogName), "catalog should be dropped");
+ Assertions.assertFalse(metalake.dropCatalog(catalogName), "catalog should be non-existent");
+ }
+
@Test
public void testCreateCatalogWithoutProperties() {
String catalogName = GravitinoITUtils.genRandomName("catalog");
@@ -159,6 +176,9 @@ public class CatalogIT extends AbstractIT {
}
Assertions.assertTrue(ArrayUtils.contains(catalogs, relCatalog));
Assertions.assertTrue(ArrayUtils.contains(catalogs, fileCatalog));
+
+ metalake.dropCatalog(relCatalogName);
+ metalake.dropCatalog(fileCatalogName);
}
private void assertCatalogEquals(Catalog catalog1, Catalog catalog2) {
diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/MetalakeIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/MetalakeIT.java
index 33eda2fbc1..4096a59d79 100644
--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/MetalakeIT.java
+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/MetalakeIT.java
@@ -167,7 +167,7 @@ public class MetalakeIT extends AbstractIT {
public void testDropMetalakes() {
GravitinoMetalake metalakeA =
client.createMetalake(metalakeNameA, "metalake A comment", Collections.emptyMap());
- assertTrue(client.dropMetalake(metalakeA.name()));
+ assertTrue(client.dropMetalake(metalakeA.name()), "metaLake should be dropped");
NameIdentifier id = NameIdentifier.of(metalakeNameA);
assertThrows(
NoSuchMetalakeException.class,
@@ -176,7 +176,7 @@ public class MetalakeIT extends AbstractIT {
});
// Metalake does not exist, so we return false
- assertFalse(client.dropMetalake(metalakeA.name()));
+ assertFalse(client.dropMetalake(metalakeA.name()), "metalake should be non-existent");
}
public void dropMetalakes() {
diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/filesystem/hadoop/GravitinoVirtualFileSystemIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/filesystem/hadoop/GravitinoVirtualFileSystemIT.java
index 5d6735c4fe..fa1050341d 100644
--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/filesystem/hadoop/GravitinoVirtualFileSystemIT.java
+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/client/filesystem/hadoop/GravitinoVirtualFileSystemIT.java
@@ -75,6 +75,9 @@ public class GravitinoVirtualFileSystemIT extends AbstractIT {
@AfterAll
public static void tearDown() throws IOException {
+ Catalog catalog = metalake.loadCatalog(catalogName);
+ catalog.asSchemas().dropSchema(schemaName, true);
+ metalake.dropCatalog(catalogName);
client.dropMetalake(metalakeName);
if (client != null) {
diff --git a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoConnectorIT.java b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoConnectorIT.java
index 2574e6c7a5..d314fa056c 100644
--- a/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoConnectorIT.java
+++ b/integration-test/src/test/java/com/datastrato/gravitino/integration/test/trino/TrinoConnectorIT.java
@@ -1081,8 +1081,11 @@ public class TrinoConnectorIT extends AbstractIT {
}
// Do not support the cascade drop
- success = catalog.asSchemas().dropSchema(schemaName, true);
- Assertions.assertFalse(success);
+ Throwable excep =
+ Assertions.assertThrows(
+ IllegalArgumentException.class, () -> catalog.asSchemas().dropSchema(schemaName, true));
+ Assertions.assertTrue(
+ excep.getMessage().contains("Iceberg does not support cascading delete operations."));
final String sql3 = String.format("show schemas in %s like '%s'", catalogName, schemaName);
success = checkTrinoHasLoaded(sql3, 30);
if (!success) {
diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestFilesetOperations.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestFilesetOperations.java
index f998b4ce47..96ebd196c2 100644
--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestFilesetOperations.java
+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestFilesetOperations.java
@@ -391,7 +391,7 @@ public class TestFilesetOperations extends JerseyTest {
.accept("application/vnd.gravitino.v1+json")
.delete();
- Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
+ Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp1.getStatus());
DropResponse dropResponse1 = resp1.readEntity(DropResponse.class);
Assertions.assertEquals(0, dropResponse1.getCode());
diff --git a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestMetalakeOperations.java b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestMetalakeOperations.java
index fd2e9a6baf..a00afd6216 100644
--- a/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestMetalakeOperations.java
+++ b/server/src/test/java/com/datastrato/gravitino/server/web/rest/TestMetalakeOperations.java
@@ -346,6 +346,18 @@ public class TestMetalakeOperations extends JerseyTest {
boolean dropped = dropResponse.dropped();
Assertions.assertTrue(dropped);
+ // Test when failed to drop metalake
+ when(metalakeManager.dropMetalake(any())).thenReturn(false);
+ Response resp2 =
+ target("/metalakes/test")
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .accept("application/vnd.gravitino.v1+json")
+ .delete();
+ Assertions.assertEquals(Response.Status.OK.getStatusCode(), resp2.getStatus());
+ DropResponse dropResponse2 = resp2.readEntity(DropResponse.class);
+ Assertions.assertEquals(0, dropResponse2.getCode());
+ Assertions.assertFalse(dropResponse2.dropped());
+
// Test throw an exception when deleting tenant.
doThrow(new RuntimeException("Internal error")).when(metalakeManager).dropMetalake(any());
diff --git a/spark-connector/spark-common/src/test/java/com/datastrato/gravitino/spark/connector/integration/test/SparkCommonIT.java b/spark-connector/spark-common/src/test/java/com/datastrato/gravitino/spark/connector/integration/test/SparkCommonIT.java
index f4251eb200..09b5d653d1 100644
--- a/spark-connector/spark-common/src/test/java/com/datastrato/gravitino/spark/connector/integration/test/SparkCommonIT.java
+++ b/spark-connector/spark-common/src/test/java/com/datastrato/gravitino/spark/connector/integration/test/SparkCommonIT.java
@@ -140,9 +140,14 @@ public abstract class SparkCommonIT extends SparkEnvIT {
@AfterAll
void cleanUp() {
- sql("USE " + getCatalogName());
- getDatabases()
- .forEach(database -> sql(String.format("DROP DATABASE IF EXISTS %s CASCADE", database)));
+ getDatabases().stream()
+ .filter(database -> !database.equals("default"))
+ .forEach(
+ database -> {
+ sql("USE " + database);
+ listTableNames().forEach(table -> dropTableIfExists(table));
+ dropDatabaseIfExists(database);
+ });
}
@Test