Light, fluffy, and always free - The AWS Local Emulator alternative
feat(glue): support GetPartitionIndexes (#3416)
Ovidiu606e7b966f11
diff --git a/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.javaindex e6a6bea468..f7e46efec3 100644--- a/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java+++ b/src/main/java/io/github/hectorvent/floci/services/glue/GlueJsonHandler.java@@ -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();diff --git a/src/test/java/io/github/hectorvent/floci/services/glue/GlueJsonHandlerTest.java b/src/test/java/io/github/hectorvent/floci/services/glue/GlueJsonHandlerTest.javaindex b045323554..cdc0bf0d5e 100644--- a/src/test/java/io/github/hectorvent/floci/services/glue/GlueJsonHandlerTest.java+++ b/src/test/java/io/github/hectorvent/floci/services/glue/GlueJsonHandlerTest.java@@ -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));+ }+@Testvoid createCrawlerWithScheduleSucceeds() throws Exception {ObjectNode request = mapper.createObjectNode();