mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(athena): paginate query execution listings (#6816)
This commit is contained in:
1 parent
a83fa9c9e4
commit
119b7e9580
5 files changed
+203
-3
No files matched your search
@@ -63,9 +63,20 @@ public class AthenaJsonHandler {
|
||||
yield Response.ok(Map.of("ResultSet", results)).build();
|
||||
}
|
||||
case "ListQueryExecutions" -> {
|
||||
yield Response.ok(Map.of("QueryExecutionIds",
|
||||
athenaService.listQueryExecutions().stream()
|
||||
.map(QueryExecution::getQueryExecutionId).toList())).build();
|
||||
Integer maxResults = Pagination.parseMaxResults(request, "MaxResults", "InvalidRequestException");
|
||||
String nextToken = Pagination.parseNextToken(request, "NextToken", "InvalidRequestException");
|
||||
JsonNode workGroup = request.get("WorkGroup");
|
||||
if (workGroup != null && !workGroup.isNull() && !workGroup.isTextual()) {
|
||||
throw new AwsException("InvalidRequestException", "WorkGroup must be a string.", 400);
|
||||
}
|
||||
PaginatedResult<QueryExecution> page = athenaService.listQueryExecutionsPage(
|
||||
region, text(request, "WorkGroup"), maxResults, nextToken);
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("QueryExecutionIds", page.items().stream().map(QueryExecution::getQueryExecutionId).toList());
|
||||
if (page.nextToken() != null) {
|
||||
response.put("NextToken", page.nextToken());
|
||||
}
|
||||
yield Response.ok(response).build();
|
||||
}
|
||||
case "StopQueryExecution" -> {
|
||||
athenaService.stopQueryExecution(request.get("QueryExecutionId").asText());
|
||||
|
||||
@@ -221,6 +221,26 @@ public class AthenaService {
|
||||
return queryStore.scan(k -> true);
|
||||
}
|
||||
|
||||
public PaginatedResult<QueryExecution> listQueryExecutionsPage(String region, String workGroup,
|
||||
Integer maxResults, String nextToken) {
|
||||
if (maxResults != null && (maxResults < 0 || maxResults > 50)) {
|
||||
throw new AwsException("InvalidRequestException", "MaxResults must be between 0 and 50.", 400);
|
||||
}
|
||||
if (nextToken != null && (nextToken.isEmpty() || nextToken.length() > 1024)) {
|
||||
throw new AwsException("InvalidRequestException", "NextToken must contain 1 to 1024 characters.", 400);
|
||||
}
|
||||
String group = workGroup == null ? DEFAULT_WORKGROUP : workGroup;
|
||||
validateWorkGroupName(group);
|
||||
getWorkGroup(group, region);
|
||||
List<QueryExecution> executions = listQueryExecutions().stream()
|
||||
.filter(execution -> group.equals(Objects.requireNonNullElse(execution.getWorkGroup(), DEFAULT_WORKGROUP)))
|
||||
.toList();
|
||||
int limit = maxResults == null || maxResults == 0 ? 50 : maxResults;
|
||||
return Pagination.paginate(executions, QueryExecution::getQueryExecutionId, limit, nextToken,
|
||||
"ListQueryExecutions:" + regionResolver.getAccountId() + ":" + region + ":" + group,
|
||||
token -> new AwsException("InvalidRequestException", "Invalid NextToken.", 400));
|
||||
}
|
||||
|
||||
public void stopQueryExecution(String id) {
|
||||
QueryExecution execution = getQueryExecution(id);
|
||||
synchronized (execution) {
|
||||
|
||||
Reference in new issue
Block a user