{"record":{"id":"f4039f491898f670","repo":"apache/druid","slug":"failed-to-handle-query-s-f4039f","errorCode":null,"errorMessage":"Failed to handle query: %s","messagePattern":"Failed to handle query: (.+?)","errorType":"http","errorClass":"DruidException","httpStatus":500,"severity":"error","filePath":"multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java","lineNumber":181,"sourceCode":"    }\n    catch (QueryException queryException) {\n      stmt.reporter().failed(queryException);\n      final DruidException underlyingException = DruidException.fromFailure(new QueryExceptionCompat(queryException));\n      return buildNonOkResponse(sqlQueryId, underlyingException);\n    }\n    catch (ForbiddenException e) {\n      log.debug(\"Got forbidden request for reason [%s]\", e.getErrorMessage());\n      return buildNonOkResponse(\n          \"forbidden\",\n          DruidException.forPersona(DruidException.Persona.USER)\n                        .ofCategory(DruidException.Category.FORBIDDEN)\n                        .build(Access.DEFAULT_ERROR_MESSAGE)\n      );\n    }\n    // Calcite throws java.lang.AssertionError at various points in planning/validation.\n    catch (AssertionError | Exception e) {\n      stmt.reporter().failed(e);\n      log.noStackTrace().warn(e, \"Failed to handle query: %s\", sqlQueryId);\n\n      return buildNonOkResponse(\n          sqlQueryId,\n          DruidException.forPersona(DruidException.Persona.DEVELOPER)\n                        .ofCategory(DruidException.Category.UNCATEGORIZED)\n                        .build(\"%s\", e.getMessage())\n      );\n    }\n    finally {\n      stmt.close();\n    }\n  }\n\n  /**\n   * Generates a task response using {@link SqlTaskStatus}.\n   */\n  private Response buildTaskResponse(Sequence<Object[]> sequence) throws IOException\n  {","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlTaskResource.java#L163-L199","documentation":"SqlTaskResource.doPost catches AssertionError and Exception around MSQ SQL query submission and returns a DEVELOPER-persona UNCATEGORIZED DruidException via buildNonOkResponse. It is a catch-all wrapper: the message carries the sqlQueryId, and the original failure is logged without stack trace and reported on the statement reporter. The real cause is whatever planning/validation/ingestion threw.","triggerScenarios":"POSTing a SQL query to /druid/v2/sql/statements when Calcite planning or validation throws (bad SQL syntax, unknown function/table, planning AssertionError), or any exception during MSQ task submission (access denial, bad context params, cluster issues).","commonSituations":"Typos in SQL, referencing nonexistent datasources/columns, unsupported SQL features,Calcite assertion failures during planning, MSQ worker/task launch failures surfacing at submit time.","solutions":["Read the returned response body / broker logs at the reported stack for the underlying cause and fix the SQL or context parameters","Check that referenced datasources, columns, and functions exist and are supported by the MSQ engine","Verify cluster health (overlord, workers) and task capacity before retrying","If an AssertionError persists, capture the full query and report it as a bug with Druid version"],"exampleFix":"// before\nclient.execute(\"SELECT NONEXISTENT_FUNC(x) FROM tbl\")\n// after\nclient.execute(\"SELECT SUM(x) FROM tbl\") // use a supported function; validate SQL first","handlingStrategy":"try-catch","validationCode":"// validate SQL before submitting\n// e.g. run EXPLAIN PLAN FOR <sql> against /druid/v2/sql first, and check datasource existence via /druid/coordinator/v1/datasources","typeGuard":"if (!(e instanceof org.apache.druid.java.util.common.DruidException)) { wrapInDruidException(e); }","tryCatchPattern":"try { submitQuery(sql); } catch (DruidException | AssertionError e) { log.error(\"MSQ submit failed for %s\", sqlQueryId, e); return Response.status(500).entity(e.getMessage()).build(); }","preventionTips":["Dry-run SQL with EXPLAIN PLAN before submission","Validate datasource/column/function names against cluster metadata","Keep context parameters within documented MSQ options","Monitor coordinator/overlord health before large submissions"],"tags":["sql","msq","query-planning","http-api"],"backgroundTag":"sql-query-failed","analyzedSha":"9b90983fd291f26935af934383ce360473179e4d","analyzedAt":"2026-09-07T13:32:30.957Z","contentChangedAt":"2026-09-07T13:32:30.957Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}