{"record":{"id":"f970e368237550a8","repo":"apache/beam","slug":"unexpected-number-type-v","errorCode":null,"errorMessage":"Unexpected number type: %v","messagePattern":"Unexpected number type: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/transforms/stats/max_switch.go","lineNumber":52,"sourceCode":"\t\treturn maxInt32Fn\n\tcase \"int64\":\n\t\treturn maxInt64Fn\n\tcase \"uint\":\n\t\treturn maxUintFn\n\tcase \"uint8\":\n\t\treturn maxUint8Fn\n\tcase \"uint16\":\n\t\treturn maxUint16Fn\n\tcase \"uint32\":\n\t\treturn maxUint32Fn\n\tcase \"uint64\":\n\t\treturn maxUint64Fn\n\tcase \"float32\":\n\t\treturn maxFloat32Fn\n\tcase \"float64\":\n\t\treturn maxFloat64Fn\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"Unexpected number type: %v\", t))\n\t}\n}\n\nfunc maxIntFn(x, y int) int {\n\tif x > y {\n\t\treturn x\n\t}\n\treturn y\n}\n\nfunc maxInt8Fn(x, y int8) int8 {\n\tif x > y {\n\t\treturn x\n\t}\n\treturn y\n}\n\nfunc maxInt16Fn(x, y int16) int16 {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/transforms/stats/max_switch.go#L34-L70","documentation":"The stats Max transform selects a combine function based on the element type name at graph construction; only numeric types (ints, uints, float32/64, etc.) are supported. If the PCollection's type is any other kind, findMaxFn panics because maximum of a non-number is undefined here.","triggerScenarios":"Using stats.Max (via findMaxFn) on a PCollection whose coder type string is not one of the handled numeric types — e.g. strings, structs, or custom types — during pipeline construction/ProcessElement setup.","commonSituations":"Accidentally feeding string or boolean collections into Max, type inference resolving to 'any'/interface after a refactor, or applying Max to encoded byte slices.","solutions":["Ensure the input PCollection to stats.Max has a concrete numeric element type (int..int64, uint..uint64, float32, float64).","Convert non-numeric data to a number before maximizing (e.g. parse or map to float64).","Check upstream type inference: use beam.Encoding / explicit typed ParDo so the type isn't interface{} or string.","Use a custom combinefn for non-numeric orderable types instead of stats.Max."],"exampleFix":"// before\nmax := stats.Max(s, strs) // strs is PCollection<string>\n// after\nnums := beam.ParDo(s, parseNum, strs) // map string -> float64 first\nmax := stats.Max(s, nums)","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"func isMaxSupported(v any) bool {\n\tswitch v.(type) {\n\tcase int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64:\n\t\treturn true\n\t}\n\treturn false\n}\n// call before stats.Max: if !isMaxSupported(firstElem) { convert or use custom combine }","tryCatchPattern":null,"preventionTips":["Feed only numeric PCollections into stats.Max","Avoid interface{} element types upstream of stats.Max","Use a custom combine function for non-numeric orderable types"],"tags":["go","apache-beam","stats","type-mismatch","panic"],"backgroundTag":"unsupported-operation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}