{"record":{"id":"eb1581710ce2b6bd","repo":"SigNoz/signoz","slug":"invalid-reduce-to-operator-s","errorCode":null,"errorMessage":"invalid reduce to operator: %s","messagePattern":"invalid reduce to operator: (.+?)","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/query-service/model/v3/v3.go","lineNumber":181,"sourceCode":"\t}\n}\n\ntype ReduceToOperator string\n\nconst (\n\tReduceToOperatorLast ReduceToOperator = \"last\"\n\tReduceToOperatorSum  ReduceToOperator = \"sum\"\n\tReduceToOperatorAvg  ReduceToOperator = \"avg\"\n\tReduceToOperatorMin  ReduceToOperator = \"min\"\n\tReduceToOperatorMax  ReduceToOperator = \"max\"\n)\n\nfunc (r ReduceToOperator) Validate() error {\n\tswitch r {\n\tcase ReduceToOperatorLast, ReduceToOperatorSum, ReduceToOperatorAvg, ReduceToOperatorMin, ReduceToOperatorMax:\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid reduce to operator: %s\", r)\n\t}\n}\n\ntype QueryType string\n\nconst (\n\tQueryTypeUnknown       QueryType = \"unknown\"\n\tQueryTypeBuilder       QueryType = \"builder\"\n\tQueryTypeClickHouseSQL QueryType = \"clickhouse_sql\"\n\tQueryTypePromQL        QueryType = \"promql\"\n)\n\nfunc (q QueryType) Validate() error {\n\tswitch q {\n\tcase QueryTypeBuilder, QueryTypeClickHouseSQL, QueryTypePromQL:\n\t\treturn nil\n\tdefault:\n\t\treturn fmt.Errorf(\"invalid query type: %s\", q)","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/model/v3/v3.go#L163-L199","documentation":"ReduceToOperator.Validate() rejects a reduce-to operator that is not one of the four supported values: last, sum, avg, min, max. The reduce-to operator controls how a time series is collapsed to a single value in builder queries (typically for table/value panels).","triggerScenarios":"Setting BuilderQuery.ReduceTo on a v3 builder query to anything other than \"last\", \"sum\", \"avg\", \"min\", or \"max\" — e.g. \"median\", \"mean\", \"p50\", or an empty string — then calling CompositeQuery.Validate() via a query API.","commonSituations":"UI version mismatch where the frontend offers a reduce function the backend doesn't support, hand-written API payloads using statistical terms not in the enum, or forgetting to set ReduceTo at all when it is required.","solutions":["Use one of the exact constants: ReduceToOperatorLast, ReduceToOperatorSum, ReduceToOperatorAvg, ReduceToOperatorMin, ReduceToOperatorMax (strings \"last\", \"sum\", \"avg\", \"min\", \"max\")","Substitute \"avg\" for mean/expected-value intents and \"last\" for gauge-style current-value intents","Align frontend and backend versions so the reduce options offered in the UI match the server enum"],"exampleFix":"// before\nbq.ReduceTo = v3.ReduceToOperator(\"mean\")\n\n// after\nbq.ReduceTo = v3.ReduceToOperatorAvg","handlingStrategy":"validation","validationCode":"switch v3.ReduceToOperator(rt) { case v3.ReduceToOperatorLast, v3.ReduceToOperatorSum, v3.ReduceToOperatorAvg, v3.ReduceToOperatorMin, v3.ReduceToOperatorMax: default: return errors.New(\"invalid reduceTo\") }","typeGuard":"func isValidReduceTo(r v3.ReduceToOperator) bool { switch r { case v3.ReduceToOperatorLast, v3.ReduceToOperatorSum, v3.ReduceToOperatorAvg, v3.ReduceToOperatorMin, v3.ReduceToOperatorMax: return true }; return false }","tryCatchPattern":null,"preventionTips":["Map UI reduce options to the five enum values before building requests","Default to ReduceToOperatorLast when the user hasn't chosen"],"tags":["go","validation","enum","query-builder","signoz"],"backgroundTag":"invalid-enum-value","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}