{"record":{"id":"4e92954cd1b621c9","repo":"apache/druid","slug":"expected-a-single-row-but-got-d-rows-please-ch","errorCode":null,"errorMessage":"Expected a single row but got [%d] rows. Please check broker logs for more information.","messagePattern":"Expected a single row but got \\[(.+?)\\] rows\\. Please check broker logs for more information\\.","errorType":"http","errorClass":"RE","httpStatus":500,"severity":"error","filePath":"multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlStatementResource.java","lineNumber":526,"sourceCode":"      if (sqlQuery.includeHeader()) {\n        responseBuilder.header(SqlResource.SQL_HEADER_RESPONSE_HEADER, SqlResource.SQL_HEADER_VALUE);\n      }\n\n      return responseBuilder.build();\n    }\n    catch (Throwable e) {\n      // make sure to close yielder if anything happened before starting to serialize the response.\n      yielder0.close();\n      throw e;\n    }\n  }\n\n  private Response buildTaskResponse(Sequence<Object[]> sequence, AuthenticationResult authenticationResult)\n  {\n    List<Object[]> rows = sequence.toList();\n    int numRows = rows.size();\n    if (numRows != 1) {\n      throw new RE(\"Expected a single row but got [%d] rows. Please check broker logs for more information.\", numRows);\n    }\n    Object[] firstRow = rows.get(0);\n    if (firstRow == null || firstRow.length != 1) {\n      throw new RE(\n          \"Expected a single column but got [%s] columns. Please check broker logs for more information.\",\n          firstRow == null ? 0 : firstRow.length\n      );\n    }\n    String taskId = String.valueOf(firstRow[0]);\n\n    Optional<SqlStatementResult> statementResult = getStatementStatus(\n        taskId,\n        authenticationResult,\n        true,\n        Action.READ,\n        false\n    );\n","sourceCodeStart":508,"sourceCodeEnd":544,"githubUrl":"https://github.com/apache/druid/blob/9b90983fd291f26935af934383ce360473179e4d/multi-stage-query/src/main/java/org/apache/druid/msq/sql/resources/SqlStatementResource.java#L508-L544","documentation":"SqlStatementResource.buildTaskResponse materializes the task-status query sequence and requires exactly one row (the row carrying the taskId). If numRows != 1 this RE is thrown. The /sql/statements endpoint expects the underlying task status query to return a single row; any other cardinality means the engine returned an unexpected result shape.","triggerScenarios":"POSTing to /druid/v2/sql/statements where the internally issued task-status query (SELECT of the ingestion task's state) yields zero rows (task not found/failed to start) or multiple rows, before extracting the taskId column.","commonSituations":"Querying the async statements API when the MSQ controller task died instantly and its status row is missing; broker/controller desync so the status lookup returns multiple entries; client bugs submitting duplicate/odd queries.","solutions":["Check broker and overlord logs for the actual task status query outcome and the MSQ task's fate.","Look up the controller task id in the overlord console to see if it failed at startup; fix the underlying query error and resubmit.","Retry the request if it was a transient desync between broker and overlord.","Verify Druid service versions are consistent so the task-status query contract is respected."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"// before using the statements API, confirm the task exists\n// GET /druid/indexer/v1/task/<controllerTaskId>/status returns 200 and non-null status","typeGuard":null,"tryCatchPattern":"try {\n  submitAsync(query);\n} catch (DruidException e) {\n  if (e.getMessage().contains(\"Expected a single row\")) {\n    checkOverlordForTaskFailure(); // task died before status row was produced\n    resubmitQuery();\n  } else { throw e; }\n}","preventionTips":["Check overlord task logs immediately when async submission returns odd row counts.","Verify the controller task started successfully before polling results.","Keep broker/overlord versions aligned."],"tags":["msq","rest-api","async-query","result-shape"],"backgroundTag":"unexpected-response-shape","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"}