apache/druid · error · DruidException
Query [ ] was not found. The query details are no longer…
Error message
Query [%s] was not found. The query details are no longer present or might not be of the type [%s]. Verify that the id is correct.
What it means
The /sql/statements/{id} status endpoint could not find a live MSQ query detail for the given query id. SqlStatementResource.doGetStatus throws a user-facing NotFoundException (queryNotFoundException) explaining that details expired, the query finished and was cleaned up, or the id belongs to a different engine/type. The HTTP response carries this DruidException.
Solutions
- Verify the queryId against the id returned by the original POST /druid/v2/sql/statements response.
- Enable durable storage so details survive and are retrievable past worker cleanup.
- Poll promptly while the query is running; once complete, consume results (and status) before the idle/retention timeout deletes them.
Example fix
// before
GET /druid/v2/sql/statements/query-abc // hours after completion, details purged
// after
// fetch the id from the POST response and poll within the retention window
String id = postResponse.getHeader("X-Druid-Query-Id");
GET /druid/v2/sql/statements/ + id Defensive patterns
Strategy: validation
Validate before calling
// keep the id returned by the POST and poll within the retention window
final String id = postResponse.getHeader("X-Druid-Query-Id");
if (id == null || id.isBlank()) {
throw new IllegalStateException("no query id captured; cannot poll status");
} Try / catch
Response resp = target.path("druid/v2/sql/statements/" + queryId).request().get();
if (resp.getStatus() == 404) {
// details expired or wrong id — re-fetch results or resubmit
} Prevention
- Persist the queryId from the POST response before polling
- Enable durable storage so details survive completion and restarts
- Consume results/status before the idle timeout purges them
- Use the SQL statements API only for MSQ query ids
When it happens
Trigger: GET /druid/v2/sql/statements/{queryId} where the id was never issued, the MSQ query completed and its details were auto-deleted (per idle timeout / durable storage cleanup), or the id refers to a native/non-MSQ query.
Common situations: Client polling a finished query after retention elapsed; using a native query id with the SQL statements API; typo'd or truncated query id; cluster restarted losing in-memory details when durable storage is not configured.
Understand the failure class
Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.
Related errors
- Expected a single column but got
- Expected a single row but got
- Failed to handle query
- Segment id [ ] is unknown
- The current user[ ] cannot view query id[ ] since the query…
AI-assisted analysis of apache/druid@9b90983fd2 (2026-09-07).
Data as JSON: /api/errors/d602e117d87fae6b.
Report an issue: GitHub.
Appendix: source
Thrown at multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlStatementResource.java:300
@Context final HttpServletRequest req
)
{
try {
AuthorizationUtils.setRequestAuthorizationAttributeIfNeeded(req);
final AuthenticationResult authenticationResult = AuthorizationUtils.authenticationResultFromRequest(req);
Optional<SqlStatementResult> sqlStatementResult = getStatementStatus(
queryId,
authenticationResult,
true,
Action.READ,
detail
);
if (sqlStatementResult.isPresent()) {
return Response.ok().entity(sqlStatementResult.get()).build();
} else {
throw queryNotFoundException(queryId);
}
}
catch (DruidException e) {
return buildNonOkResponse(e);
}
catch (ForbiddenException e) {
log.debug("Got forbidden request for reason [%s]", e.getErrorMessage());
return buildNonOkResponse(Forbidden.exception());
}
catch (Exception e) {
log.warn(e, "Failed to handle query [%s]", queryId);
return buildNonOkResponse(DruidException.forPersona(DruidException.Persona.DEVELOPER)
.ofCategory(DruidException.Category.UNCATEGORIZED)
.build(e, "Failed to handle query [%s]", queryId));
}
}
@GETView on GitHub (pinned to 9b90983fd2)