diff --git a/src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java b/src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java index 9eb04f11c9..3f075f3006 100644 --- a/src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java +++ b/src/main/java/io/github/hectorvent/floci/services/athena/AthenaService.java @@ -73,7 +73,8 @@ public class AthenaService { resolvedContext.setCatalog(DEFAULT_CATALOG); } - // Ensure output location has a trailing slash so floci-duck writes into the prefix + // AWS reports the result CSV object itself as the OutputLocation, not a + // directory prefix — the same key is written and returned to the client. String outputLocation = resolveOutputLocation(resultConfiguration, id); ResultConfiguration resolvedResult = new ResultConfiguration(outputLocation); @@ -93,7 +94,7 @@ public class AthenaService { vertx.executeBlocking(() -> { String setupDdl = buildGlueDdl(database); ensureOutputBucket(outputLocation); - duckClient.execute(query, setupDdl, outputLocation + "results.csv"); + duckClient.execute(query, setupDdl, outputLocation); return null; }).onSuccess(v -> { execution.getStatus().setState(QueryExecutionState.SUCCEEDED); @@ -279,7 +280,7 @@ public class AthenaService { String base = (rc != null && rc.getOutputLocation() != null && !rc.getOutputLocation().isBlank()) ? rc.getOutputLocation() : "s3://" + DEFAULT_OUTPUT_BUCKET + "/results/"; - return base.endsWith("/") ? base + queryId + "/" : base + "/" + queryId + "/"; + return base.endsWith("/") ? base + queryId + ".csv" : base + "/" + queryId + ".csv"; } private WorkGroupConfiguration normalizeWorkGroupConfiguration(CreateWorkGroupConfigurationRequest configuration) { diff --git a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java index 926143c0ea..a83ea6bbf1 100644 --- a/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/athena/AthenaIntegrationTest.java @@ -377,4 +377,35 @@ class AthenaIntegrationTest { .body("TableMetadata.CreateTime", instanceOf(Number.class)) .body("TableMetadata.LastAccessTime", instanceOf(Number.class)); } + + @Test + @Order(13) + void outputLocationIsTheResultCsvObjectKey() { + String id = given() + .header("X-Amz-Target", "AmazonAthena.StartQueryExecution") + .contentType(CONTENT_TYPE) + .body(""" + { + "QueryString": "SELECT 1", + "ResultConfiguration": { "OutputLocation": "s3://athena-location-test/out/" } + } + """) + .when() + .post("/") + .then() + .statusCode(200) + .extract().path("QueryExecutionId"); + + // AWS reports the result CSV object itself, not a directory prefix + given() + .header("X-Amz-Target", "AmazonAthena.GetQueryExecution") + .contentType(CONTENT_TYPE) + .body("{ \"QueryExecutionId\": \"" + id + "\" }") + .when() + .post("/") + .then() + .statusCode(200) + .body("QueryExecution.ResultConfiguration.OutputLocation", + equalTo("s3://athena-location-test/out/" + id + ".csv")); + } }