fix(athena): route database DDL to Glue (#2757)

* fix(athena): route database DDL to Glue

* fix(athena): preserve DDL execution failures
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-08-30 18:26:48 -04:00
1 parent 881695ea3b
commit 2480daaa09
5 files changed
+371 -14

No files matched your search

@@ -4,6 +4,8 @@ import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.*;
import java.util.Map;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.*;
@@ -408,4 +410,110 @@ class AthenaIntegrationTest {
.body("QueryExecution.ResultConfiguration.OutputLocation",
equalTo("s3://athena-location-test/out/" + id + ".csv"));
}
@Test
@Order(14)
void createDatabaseDdlUpdatesGlueCatalogWithoutResultOutput() {
String query = """
CREATE DATABASE IF NOT EXISTS workspace_dev_test
COMMENT 'Created through Athena'
LOCATION 's3://bucket/path'
WITH DBPROPERTIES ('owner'='integration-test')
""";
String id = given()
.header("X-Amz-Target", "AmazonAthena.StartQueryExecution")
.contentType(CONTENT_TYPE)
.body(Map.of("QueryString", query))
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("QueryExecutionId");
given()
.header("X-Amz-Target", "AmazonAthena.GetQueryExecution")
.contentType(CONTENT_TYPE)
.body("{ \"QueryExecutionId\": \"" + id + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("QueryExecution.Status.State", equalTo("SUCCEEDED"))
.body("QueryExecution.StatementType", equalTo("DDL"))
.body("QueryExecution.ResultConfiguration", nullValue());
given()
.header("X-Amz-Target", "AWSGlue.GetDatabase")
.contentType(CONTENT_TYPE)
.body("{ \"Name\": \"workspace_dev_test\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("Database.Name", equalTo("workspace_dev_test"))
.body("Database.Description", equalTo("Created through Athena"))
.body("Database.LocationUri", equalTo("s3://bucket/path"))
.body("Database.Parameters.owner", equalTo("integration-test"));
given()
.header("X-Amz-Target", "AmazonAthena.GetQueryResults")
.contentType(CONTENT_TYPE)
.body("{ \"QueryExecutionId\": \"" + id + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("ResultSet.Rows", empty())
.body("ResultSet.ResultSetMetadata.ColumnInfo", empty());
String repeatId = given()
.header("X-Amz-Target", "AmazonAthena.StartQueryExecution")
.contentType(CONTENT_TYPE)
.body(Map.of("QueryString", query))
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("QueryExecutionId");
given()
.header("X-Amz-Target", "AmazonAthena.GetQueryExecution")
.contentType(CONTENT_TYPE)
.body("{ \"QueryExecutionId\": \"" + repeatId + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("QueryExecution.Status.State", equalTo("SUCCEEDED"));
}
@Test
@Order(15)
void malformedCreateDatabaseDdlIsRecordedAsFailedExecution() {
String id = given()
.header("X-Amz-Target", "AmazonAthena.StartQueryExecution")
.contentType(CONTENT_TYPE)
.body(Map.of("QueryString", """
CREATE DATABASE invalid_properties_test
WITH DBPROPERTIES ('owner'='integration-test', )
"""))
.when()
.post("/")
.then()
.statusCode(200)
.extract().path("QueryExecutionId");
given()
.header("X-Amz-Target", "AmazonAthena.GetQueryExecution")
.contentType(CONTENT_TYPE)
.body("{ \"QueryExecutionId\": \"" + id + "\" }")
.when()
.post("/")
.then()
.statusCode(200)
.body("QueryExecution.Status.State", equalTo("FAILED"))
.body("QueryExecution.Status.StateChangeReason", equalTo("Invalid database properties"))
.body("QueryExecution.StatementType", equalTo("DDL"))
.body("QueryExecution.ResultConfiguration", nullValue());
}
}
@@ -0,0 +1,63 @@
package io.github.hectorvent.floci.services.floci.duck;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sun.net.httpserver.HttpServer;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
import io.github.hectorvent.floci.core.common.docker.DockerHostResolver;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
class FlociDuckClientServiceTest {
private HttpServer server;
@AfterEach
void stopServer() {
if (server != null) {
server.stop(0);
}
}
@Test
void executeOmitsNullOutputPath() throws Exception {
ObjectMapper mapper = new ObjectMapper();
AtomicReference<JsonNode> requestBody = new AtomicReference<>();
server = HttpServer.create(new InetSocketAddress(0), 0);
server.createContext("/execute", exchange -> {
String body = new String(exchange.getRequestBody().readAllBytes(), StandardCharsets.UTF_8);
requestBody.set(mapper.readTree(body));
exchange.sendResponseHeaders(200, -1);
exchange.close();
});
server.start();
FlociDuckManager duckManager = mock(FlociDuckManager.class);
EmulatorConfig config = mock(EmulatorConfig.class);
EmbeddedDnsServer embeddedDnsServer = mock(EmbeddedDnsServer.class);
DockerHostResolver dockerHostResolver = mock(DockerHostResolver.class);
when(duckManager.ensureReady()).thenReturn("http://localhost:" + server.getAddress().getPort());
when(config.baseUrl()).thenReturn("http://localhost:4566");
when(config.defaultRegion()).thenReturn("us-east-1");
when(config.hostname()).thenReturn(Optional.of("floci.internal"));
when(embeddedDnsServer.getServerIp()).thenReturn(Optional.of("127.0.0.1"));
FlociDuckClient client = new FlociDuckClient(
duckManager, config, embeddedDnsServer, dockerHostResolver, mapper);
client.execute("CREATE VIEW example AS SELECT 1", "", null);
assertEquals("CREATE VIEW example AS SELECT 1", requestBody.get().path("sql").asText());
assertFalse(requestBody.get().has("output_s3_path"));
}
}