{"record":{"id":"75d358a9a0390eea","repo":"SigNoz/signoz","slug":"error-in-reading-data","errorCode":null,"errorMessage":"error in reading data","messagePattern":"error in reading data","errorType":"exception","errorClass":"model.ApiError","httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":329,"sourceCode":"\tquery := fmt.Sprintf(`SELECT name, serviceName, max(time) as ts FROM %s.%s WHERE time >= @start`, r.TraceDB, r.topLevelOperationsTable)\n\tif len(services) > 0 {\n\t\tquery += ` AND serviceName IN @services`\n\t}\n\tquery += ` GROUP BY name, serviceName ORDER BY ts DESC LIMIT 5000`\n\n\trows, err := r.db.Query(ctx, query, clickhouse.Named(\"start\", start), clickhouse.Named(\"services\", services))\n\n\tif err != nil {\n\t\tr.logger.Error(\"Error in processing sql query\", errorsV2.Attr(err))\n\t\treturn nil, &model.ApiError{Typ: model.ErrorExec, Err: fmt.Errorf(\"error in processing sql query\")}\n\t}\n\n\tdefer rows.Close()\n\tfor rows.Next() {\n\t\tvar name, serviceName string\n\t\tvar t time.Time\n\t\tif err := rows.Scan(&name, &serviceName, &t); err != nil {\n\t\t\treturn nil, &model.ApiError{Typ: model.ErrorInternal, Err: fmt.Errorf(\"error in reading data\")}\n\t\t}\n\t\tif _, ok := operations[serviceName]; !ok {\n\t\t\toperations[serviceName] = []string{\"overflow_operation\"}\n\t\t}\n\t\toperations[serviceName] = append(operations[serviceName], name)\n\t}\n\treturn &operations, nil\n}\n\nfunc (r *ClickHouseReader) buildResourceSubQuery(ctx context.Context, orgID valuer.UUID, tags []model.TagQueryParam, svc string, start, end time.Time) (string, error) {\n\t// assuming all will be resource attributes.\n\t// and resource attributes are string for traces\n\tfilterSet := v3.FilterSet{}\n\tfor _, tag := range tags {\n\t\t// skip the collector id as we don't add it to traces\n\t\tif tag.Key == \"signoz.collector.id\" {\n\t\t\tcontinue\n\t\t}","sourceCodeStart":311,"sourceCodeEnd":347,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L311-L347","documentation":"ApiError (ErrorInternal) from GetTopLevelOperations when rows.Scan of (name, serviceName, timestamp) fails while iterating results of the top-level operations query — the query executed but returned rows incompatible with the scan targets.","triggerScenarios":"Result columns for name/serviceName/time arrive with unexpected types or NULLs — typically after a schema/type change in the traces table or a driver deserialization mismatch — causing Scan to error inside the rows.Next loop.","commonSituations":"Version mismatches between clickhouse-go driver and server, schema drift after upgrades altering column types, or corrupted/partial results from an unhealthy CH node.","solutions":["Inspect the wrapped scan error in debugging/logs","DESCRIBE the traces table and verify name/serviceName/ts column types match expectations","Upgrade/align the clickhouse driver and server versions","Re-run against a healthy ClickHouse node"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Verify expected columns/types before scanning-heavy calls\ncols := describeTable(ctx, ch, r.TraceDB, r.traceTableName)\nrequireColumns(cols, map[string]string{\"name\":\"String\",\"serviceName\":\"String\"})","typeGuard":"func isReadDataErr(apiErr *model.ApiError) bool {\n    return apiErr != nil && apiErr.Typ == model.ErrorInternal && strings.Contains(apiErr.Err.Error(), \"error in reading data\")\n}","tryCatchPattern":"ops, apiErr := reader.GetTopLevelOperations(ctx, params)\nif isReadDataErr(apiErr) {\n    // likely type drift: pin driver/server versions and re-verify schema\n    return nil, apiErr\n}","preventionTips":["Pin clickhouse-go driver versions","Run DESCRIBE checks in startup probes after upgrades","Treat scan failures as schema-drift incidents"],"tags":["clickhouse","row-scan","traces","schema-drift"],"backgroundTag":"row-scan-type-mismatch","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}