mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(athena): report the result CSV object key as OutputLocation (#1895)
GetQueryExecution reported OutputLocation as a directory prefix (<base>/<queryId>/) 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 <QueryID>.csv and saves them directly to the result location for API queries. Resolve the location to <base>/<queryId>.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
This commit is contained in:
1 parent
b60a58fab6
commit
418ec1bdae
2 files changed
+35
-3
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user