{"record":{"id":"69ea34c97282f282","repo":"prestodb/presto","slug":"druid-broker-result-error","errorCode":"DRUID_BROKER_RESULT_ERROR","errorMessage":"${rootNode.findValue(\"errorMessage\").asText()}","messagePattern":"\\$\\{rootNode\\.findValue\\(\"errorMessage\"\\)\\.asText\\(\\)\\}","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-druid/src/main/java/com/facebook/presto/druid/DruidBrokerPageSource.java","lineNumber":127,"sourceCode":"        if (finished) {\n            return null;\n        }\n\n        long start = System.nanoTime();\n        boolean columnHandlesHasErrorMessageField = columnHandles.stream().anyMatch(\n                handle -> ((DruidColumnHandle) handle).getColumnName().equals(\"errorMessage\"));\n        try {\n            String readLine;\n            while ((readLine = responseStream.readLine()) != null) {\n                // if read a blank line,it means read finish\n                if (readLine.isEmpty()) {\n                    finished = true;\n                    break;\n                }\n                else {\n                    JsonNode rootNode = OBJECT_MAPPER.readTree(readLine);\n                    if (rootNode.has(\"errorMessage\") && !columnHandlesHasErrorMessageField) {\n                        throw new PrestoException(DRUID_BROKER_RESULT_ERROR, rootNode.findValue(\"errorMessage\").asText());\n                    }\n                    for (int i = 0; i < columnHandles.size(); i++) {\n                        Type type = columnTypes.get(i);\n                        BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);\n                        JsonNode value = rootNode.get(((DruidColumnHandle) columnHandles.get(i)).getColumnName());\n                        if (value == null || value.isNull()) {\n                            blockBuilder.appendNull();\n                            continue;\n                        }\n                        if (type instanceof BigintType) {\n                            type.writeLong(blockBuilder, value.longValue());\n                        }\n                        else if (type instanceof DoubleType) {\n                            type.writeDouble(blockBuilder, value.doubleValue());\n                        }\n                        else if (type instanceof RealType) {\n                            type.writeLong(blockBuilder, floatToRawIntBits(value.floatValue()));\n                        }","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-druid/src/main/java/com/facebook/presto/druid/DruidBrokerPageSource.java#L109-L145","documentation":"This PrestoException (DRUID_BROKER_RESULT_ERROR) is thrown by DruidBrokerPageSource.getNextPage when a line of the Druid broker's newline-delimited JSON response contains an \"errorMessage\" field. Druid's /druid/v2/sql endpoint returns per-row error objects (e.g. {\"queryNumber\":..., \"errorMessage\":\"...\"}) when the SQL query fails server-side, and the connector surfaces that message directly to the user instead of returning bad data. The check is skipped if the query itself selected a column literally named \"errorMessage\".","triggerScenarios":"Streaming OBJECT_LINES results from DruidBrokerPageSource.getNextPage when any parsed JSON line has a non-null \"errorMessage\" field and no selected column is named \"errorMessage\" — i.e. the Druid broker rejected or failed the SQL query mid-stream.","commonSituations":"Invalid DQL/SQL sent to Druid (unknown column, bad function, syntax error); Druid query timeout or resource limits (maxScatterGatherBytes, query quotas); broker unable to reach historical nodes; Druid version/config changes altering the SQL API; the table or datasource being queried does not exist or segments are unavailable.","solutions":["Read the embedded errorMessage in the exception text — it is Druid's own reason (e.g. unknown column, timeout) and fix the query accordingly.","Validate the SQL/datasource by running the query directly against the Druid broker (e.g. curl POST to /druid/v2/sql) to confirm the failure is server-side.","Check Druid broker logs and query timeout/resource-limit configs (maxScatterGatherBytes, druid.query.timeouts), and raise them if the query is being killed.","If your table intentionally has a column named errorMessage, note the connector will not treat it as a failure signal; otherwise rename or avoid shadowing the reserved field.","Refresh Presto's metadata cache (SYSTEM.drop_metadata_cache or restart) if the datasource was recently dropped/recreated."],"exampleFix":"// before: query fails server-side with unclear failure\nSELECT unknown_col FROM druid.mytable\n\n// after: verify the column exists first, or use INFORMATION_SCHEMA\nSELECT COLUMN_NAME FROM druid.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'mytable';\n-- then query only existing columns, e.g.\nSELECT real_col FROM druid.mytable","handlingStrategy":"try-catch","validationCode":"// Validate the datasource/columns before querying:\n// SELECT COLUMN_NAME FROM druid.INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'mytable';\n// Ensure every referenced column exists and no query fails server-side.\ncurl -s -XPOST 'http://druid-broker:8082/druid/v2/sql' \\\n  -H 'Content-Type: application/json' \\\n  -d '{\"query\":\"SELECT 1 FROM mytable LIMIT 1\"}'","typeGuard":null,"tryCatchPattern":"try {\n    connector.execute(query);\n} catch (PrestoException e) {\n    if (DRUID_BROKER_RESULT_ERROR.toErrorCode().equals(e.getErrorCode())) {\n        // e.getMessage() is Druid's errorMessage payload — inspect query validity/limits\n        log.error(\"Druid query failed server-side: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Test queries directly against the Druid broker before running them in Presto","Verify column names via druid.INFORMATION_SCHEMA.COLUMNS before querying","Watch Druid broker logs for query failures and limit breaches","Avoid naming application columns errorMessage to prevent signal shadowing"],"tags":["druid","presto","query-failed","server-side-error","newline-json"],"backgroundTag":"druid-query-error-message","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}