mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat: support Glue DeleteDatabase (#1181)
This commit is contained in:
1 parent
701d8f4ae9
commit
10e28f33c2
6 files changed
+103
-4
No files matched your search
+40
@@ -11,6 +11,8 @@ import org.junit.jupiter.api.TestMethodOrder;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
|
||||
@@ -343,4 +345,42 @@ class GlueCatalogSchemaBindingIntegrationTest {
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("EntityNotFoundException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(9)
|
||||
void deleteDatabaseRemovesCatalogDatabase() {
|
||||
String database = "database-to-delete";
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.CreateDatabase")
|
||||
.body("{ \"DatabaseInput\": { \"Name\": \"" + database + "\" } }")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.CreateTable")
|
||||
.body("""
|
||||
{
|
||||
"DatabaseName": "%s",
|
||||
"TableInput": {
|
||||
"Name": "table_to_delete",
|
||||
"StorageDescriptor": {
|
||||
"Location": "s3://bucket/delete/"
|
||||
}
|
||||
}
|
||||
}
|
||||
""".formatted(database))
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.DeleteDatabase")
|
||||
.body("{ \"Name\": \"" + database + "\" }")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
given().contentType(CONTENT_TYPE)
|
||||
.header("X-Amz-Target", "AWSGlue.GetDatabases")
|
||||
.body("{}")
|
||||
.when().post("/").then()
|
||||
.statusCode(200)
|
||||
.body("DatabaseList.Name", not(hasItem(database)));
|
||||
}
|
||||
}
|
||||
@@ -44,16 +44,20 @@ class GlueServiceTest {
|
||||
|
||||
private GlueService glueService;
|
||||
private GlueSchemaRegistryService schemaRegistryService;
|
||||
private StorageBackend<String, Table> tableStore;
|
||||
private StorageBackend<String, Partition> partitionStore;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
RegionResolver regionResolver = new RegionResolver(REGION, ACCOUNT_ID);
|
||||
StorageFactory storageFactory = new InMemoryStorageFactory();
|
||||
schemaRegistryService = new GlueSchemaRegistryService(storageFactory, regionResolver);
|
||||
tableStore = new InMemoryStorage<>();
|
||||
partitionStore = new InMemoryStorage<>();
|
||||
glueService = new GlueService(
|
||||
new InMemoryStorage<String, Database>(),
|
||||
new InMemoryStorage<String, Table>(),
|
||||
new InMemoryStorage<String, Partition>(),
|
||||
tableStore,
|
||||
partitionStore,
|
||||
new InMemoryStorage<String, UserDefinedFunction>(),
|
||||
schemaRegistryService, regionResolver);
|
||||
glueService.createDatabase(new Database("db1"));
|
||||
@@ -230,6 +234,45 @@ class GlueServiceTest {
|
||||
assertEquals("true", fetched.getParameters().get("presto_view"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteDatabaseDeletesDatabaseTablesAndPartitions() {
|
||||
Table table = new Table();
|
||||
table.setName("plain");
|
||||
glueService.createTable("db1", table);
|
||||
|
||||
Partition partition = new Partition();
|
||||
partition.setValues(java.util.List.of("2026"));
|
||||
glueService.createPartition("db1", "plain", partition);
|
||||
|
||||
glueService.deleteDatabase("db1");
|
||||
|
||||
assertThrows(AwsException.class, () -> glueService.getDatabase("db1"));
|
||||
assertThrows(AwsException.class, () -> glueService.getTable("db1", "plain"));
|
||||
assertTrue(tableStore.scan(k -> true).isEmpty());
|
||||
assertTrue(partitionStore.scan(k -> true).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteDatabaseDoesNotDeleteSimilarDatabaseNames() {
|
||||
glueService.createDatabase(new Database("a"));
|
||||
glueService.createDatabase(new Database("a:b"));
|
||||
Table similarDatabaseTable = new Table();
|
||||
similarDatabaseTable.setName("t");
|
||||
glueService.createTable("a:b", similarDatabaseTable);
|
||||
|
||||
glueService.deleteDatabase("a");
|
||||
|
||||
assertEquals("t", glueService.getTable("a:b", "t").getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deleteDatabaseForMissingDatabaseThrows() {
|
||||
AwsException ex = assertThrows(AwsException.class,
|
||||
() -> glueService.deleteDatabase("missing"));
|
||||
|
||||
assertEquals("EntityNotFoundException", ex.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void getTableVersionsReturnsEmptyListForAthenaCompatibility() {
|
||||
assertTrue(glueService.getTableVersions().isEmpty());
|
||||
|
||||
Reference in new issue
Block a user