From 418ec1bdae3dde388ddda7d235cf13f3d5f6f485 Mon Sep 17 00:00:00 2001
From: soreavis <263610811+soreavis@users.noreply.github.com>
Date: Thu, 30 Jul 2026 04:46:29 +0200
Subject: [PATCH] fix(athena): report the result CSV object key as
OutputLocation (#1895)
GetQueryExecution reported OutputLocation as a directory prefix
(//) while the result was written to results.csv
inside it, so a client GET on the reported location failed with
NoSuchKey. Real Athena names result files .csv and saves
them directly to the result location for API queries.
Resolve the location to /.csv and write the CSV to
exactly that key. The reader lists by prefix, so it finds the new
form and still reads executions persisted with the old prefix form.
Closes #1752
---
.../floci/services/athena/AthenaService.java | 7 +++--
.../athena/AthenaIntegrationTest.java | 31 +++++++++++++++++++
2 files changed, 35 insertions(+), 3 deletions(-)
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"));
+ }
}