{"record":{"id":"e06ea53933178f9d","repo":"SigNoz/signoz","slug":"error-building-clickhouse-query-v","errorCode":null,"errorMessage":"error building clickhouse query: %v","messagePattern":"error building clickhouse query: (.+?)","errorType":"http","errorClass":"model.ApiError","httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/http_handler.go","lineNumber":4032,"sourceCode":"\t}\n\taH.WriteJSON(w, r, field)\n}\n\nfunc (aH *APIHandler) getQueueOverview(w http.ResponseWriter, r *http.Request) {\n\n\tqueueListRequest, apiErr := ParseQueueBody(r)\n\n\tif apiErr != nil {\n\t\taH.logger.ErrorContext(r.Context(), \"failed to parse queue body\", errors.Attr(apiErr.Err))\n\t\tRespondError(w, apiErr, nil)\n\t\treturn\n\t}\n\n\tchq, err := queues2.BuildOverviewQuery(queueListRequest)\n\n\tif err != nil {\n\t\taH.logger.ErrorContext(r.Context(), \"failed to build queue overview query\", errors.Attr(err))\n\t\tRespondError(w, &model.ApiError{Typ: model.ErrorInternal, Err: fmt.Errorf(\"error building clickhouse query: %v\", err)}, nil)\n\t\treturn\n\t}\n\n\tresults, err := aH.reader.GetListResultV3(r.Context(), chq.Query)\n\tif err != nil {\n\t\tRespondError(w, model.BadRequest(err), nil)\n\t\treturn\n\t}\n\n\taH.Respond(w, results)\n}\n\nfunc (aH *APIHandler) getDomainList(w http.ResponseWriter, r *http.Request) {\n\t// Extract claims from context for organization ID\n\tclaims, err := authtypes.ClaimsFromContext(r.Context())\n\tif err != nil {\n\t\trender.Error(w, err)\n\t\treturn","sourceCodeStart":4014,"sourceCodeEnd":4050,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/http_handler.go#L4014-L4050","documentation":"This 500 is returned from the queue overview endpoint when queues2.BuildOverviewQuery fails to translate the validated QueueListRequest into a ClickHouse query. BuildOverviewQuery constructs SQL from user-supplied filters, group-by, and time-range parameters; invalid combinations (unknown group-by keys, bad filter columns, inverted or zero time ranges, unsupported aggregation) surface here rather than during request parsing.","triggerScenarios":"POST to the queue overview/list API with an invalid groupBy field, a filter referencing a nonexistent ClickHouse column, an unreadable start/end timestamp pair, or a queue-name pattern the query builder cannot escape, causing BuildOverviewRequest (earlier validation passes) but BuildOverviewQuery to error.","commonSituations":"Frontend sending a newer/older request schema than the query-service expects after a version mismatch; user-crafted filter expressions with reserved SQL characters; empty or malformed time range slipped through earlier validation; column renamed in a ClickHouse migration but request still references the old name.","solutions":["Inspect the server log line 'failed to build queue overview query' — errors.Attr(err) carries the exact builder failure","Check the request payload's groupBy, filters, and time range against the queues2 package's supported fields for your SigNoz version","Repro with a minimal request (valid time range, no filters, default groupBy) and add fields back one at a time to isolate the offending parameter","If schema drift is suspected (old column names), align frontend payload with the query-service version or upgrade both together"],"exampleFix":"// before\n{\"groupBy\": [\"bogus_field\"], \"filters\": [{\"column\": \"no_such_col\", \"op\": \"eq\", \"value\": 1}]}\n\n// after\n{\"groupBy\": [\"destination\"], \"filters\": [{\"column\": \"destination\", \"op\": \"eq\", \"value\": \"orders\"}], \"start\": 1710000000, \"end\": 1710086400}","handlingStrategy":"validation","validationCode":"const SUPPORTED_GROUPBY = new Set(['destination','name','status']);\nfunction validateQueueReq(req) {\n  if (!req.start || !req.end || req.end <= req.start) return 'invalid time range';\n  for (const g of req.groupBy || []) if (!SUPPORTED_GROUPBY.has(g)) return `unsupported groupBy: ${g}`;\n  return null;\n}","typeGuard":"function isQueueListRequest(r: unknown): r is QueueListRequest {\n  const q = r as QueueListRequest;\n  return typeof q?.start === 'number' && typeof q?.end === 'number' && q.end > q.start &&\n    (q.groupBy ?? []).every(g => typeof g === 'string');\n}","tryCatchPattern":"try {\n  const res = await fetch('/api/v1/queues/overview', {method:'POST', body: JSON.stringify(req)});\n  if (res.status === 500) console.error('query build failed — check groupBy/filters payload');\n} catch (e) { /* network */ }","preventionTips":["Validate groupBy values against the supported set before sending","Always send explicit, ordered start/end timestamps","Keep frontend request schema in lockstep with the query-service version","Log the full rejected payload on 500 to speed diagnosis"],"tags":["clickhouse","query-builder","kafka-queues","signoz","validation"],"backgroundTag":"query-build-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}