mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(glue): support GetPartitionIndexes (#3416)
Reading a table's partition indexes failed as an unsupported action, which makes a Glue table unmanageable as infrastructure: the Terraform AWS provider reads the indexes after creating a table and again on every refresh, so the create reports an error and every later plan fails on the same call. The table itself is fine - only the read of its indexes is missing - so the resource lands in state and then cannot be planned. Return an empty descriptor list. No index can exist while CreatePartitionIndex is unsupported, so empty is the accurate answer rather than a placeholder, and it is the answer a client reading a table's indexes needs. The table is resolved first so that a missing one is reported as missing rather than as a table that happens to have no indexes.
This commit is contained in:
1 parent
543bde7d5d
commit
606e7b966f
2 files changed
+56
No files matched your search
@@ -84,6 +84,16 @@ public class GlueJsonHandler {
|
||||
Table table = glueService.getTable(dbName, tableName);
|
||||
yield Response.ok(Map.of("Table", table)).build();
|
||||
}
|
||||
case "GetPartitionIndexes" -> {
|
||||
String dbName = request.get("DatabaseName").asText();
|
||||
String tableName = request.get("TableName").asText();
|
||||
// Resolve the table so a missing one is reported as such rather than as an empty
|
||||
// index list. No index can exist until CreatePartitionIndex is supported, so the
|
||||
// list is empty for every table that does resolve - which is the answer a client
|
||||
// reading a table's indexes needs, rather than an unsupported-action failure.
|
||||
glueService.getTable(dbName, tableName);
|
||||
yield Response.ok(Map.of("PartitionIndexDescriptorList", List.of())).build();
|
||||
}
|
||||
case "GetTables" -> {
|
||||
String dbName = request.get("DatabaseName").asText();
|
||||
yield Response.ok(Map.of("TableList", glueService.getTables(dbName))).build();
|
||||
|
||||
@@ -17,6 +17,7 @@ import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class GlueJsonHandlerTest {
|
||||
@@ -40,6 +41,51 @@ class GlueJsonHandlerTest {
|
||||
handler = new GlueJsonHandler(glueService, schemaRegistryService, mapper);
|
||||
}
|
||||
|
||||
private void createDatabaseAndTable(String dbName, String tableName) throws Exception {
|
||||
ObjectNode createDb = mapper.createObjectNode();
|
||||
createDb.putObject("DatabaseInput").put("Name", dbName);
|
||||
assertEquals(200, handler.handle("CreateDatabase", createDb, REGION).getStatus());
|
||||
|
||||
ObjectNode createTable = mapper.createObjectNode();
|
||||
createTable.put("DatabaseName", dbName);
|
||||
createTable.putObject("TableInput").put("Name", tableName);
|
||||
assertEquals(200, handler.handle("CreateTable", createTable, REGION).getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
* A client reading a table's partition indexes needs an answer, not an unsupported-action
|
||||
* failure: the Terraform AWS provider reads them after creating a table and on every refresh,
|
||||
* so without this a Glue table cannot be managed as a resource at all.
|
||||
*/
|
||||
@Test
|
||||
void getPartitionIndexesReturnsAnEmptyListForAnExistingTable() throws Exception {
|
||||
createDatabaseAndTable("indexes_db", "events");
|
||||
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("DatabaseName", "indexes_db");
|
||||
request.put("TableName", "events");
|
||||
|
||||
Response response = handler.handle("GetPartitionIndexes", request, REGION);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> body = (Map<String, Object>) response.getEntity();
|
||||
assertTrue(body.containsKey("PartitionIndexDescriptorList"));
|
||||
assertTrue(((java.util.List<?>) body.get("PartitionIndexDescriptorList")).isEmpty());
|
||||
}
|
||||
|
||||
/** A missing table is reported as missing, not as a table that happens to have no indexes. */
|
||||
@Test
|
||||
void getPartitionIndexesOnAMissingTableFails() throws Exception {
|
||||
createDatabaseAndTable("indexes_db2", "events");
|
||||
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("DatabaseName", "indexes_db2");
|
||||
request.put("TableName", "absent");
|
||||
|
||||
assertThrows(Exception.class, () -> handler.handle("GetPartitionIndexes", request, REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void createCrawlerWithScheduleSucceeds() throws Exception {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
|
||||
Reference in new issue
Block a user