{"record":{"id":"48b054ba3e955fc5","repo":"apache/beam","slug":"unexpected-number-type-v-min-switch","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/min_switch.go","lineNumber":52,"sourceCode":"\t\treturn minInt32Fn\n\tcase \"int64\":\n\t\treturn minInt64Fn\n\tcase \"uint\":\n\t\treturn minUintFn\n\tcase \"uint8\":\n\t\treturn minUint8Fn\n\tcase \"uint16\":\n\t\treturn minUint16Fn\n\tcase \"uint32\":\n\t\treturn minUint32Fn\n\tcase \"uint64\":\n\t\treturn minUint64Fn\n\tcase \"float32\":\n\t\treturn minFloat32Fn\n\tcase \"float64\":\n\t\treturn minFloat64Fn\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"Unexpected number type: %v\", t))\n\t}\n}\n\nfunc minIntFn(x, y int) int {\n\tif x < y {\n\t\treturn x\n\t}\n\treturn y\n}\n\nfunc minInt8Fn(x, y int8) int8 {\n\tif x < y {\n\t\treturn x\n\t}\n\treturn y\n}\n\nfunc minInt16Fn(x, y int16) int16 {","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/transforms/stats/min_switch.go#L34-L70","documentation":"stats.Min uses a switch on the element type's kind to select a specialized min combine function (minIntFn, minUint64Fn, minFloat32Fn, etc.). If the PCollection's element type is not one of the supported numeric kinds, findSumFn/findMinFn panics with this message. The library only supports Go's fixed numeric types for min/max aggregations.","triggerScenarios":"Calling stats.Min(s, col) (or MinPerKey) on a PCollection whose element type is not a supported numeric kind, e.g. a string, struct, interface, bool, uintptr, or a user-defined named type whose reflect.Kind still resolves outside the switch's cases.","commonSituations":"Aggregating a string or bool column by mistake; passing a custom numeric-like struct instead of a raw numeric type; type inference picking 'interface{}' after a generic DoFn; copying pipeline code from an int pipeline to a big.Float/decimal type.","solutions":["Check the PCollection element type with beam.FindElementTyepOrDie or by inspecting your DoFn's output type; ensure it is int/int8..64, uint..64, float32, or float64.","Convert non-numeric or decimal data to a supported numeric type before stats.Min, e.g. map to float64.","For custom ordering semantics, use transforms/top (top.Smallest) with your own less function instead of stats.Min."],"exampleFix":"// before\n// stringCol: PCollection<string>\nbeam.ParDo(s, func(s string) string { return s }, stringCol)\nstats.Min(s, stringCol) // panics: Unexpected number type: string\n\n// after\nnumbers := beam.ParDo(s, func(s string) float64 {\n    f, _ := strconv.ParseFloat(s, 64)\n    return f\n}, stringCol)\nstats.Min(s, numbers)","handlingStrategy":"validation","validationCode":"t := reflect.TypeOf(el)\nswitch t.Kind() {\ncase reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n    reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,\n    reflect.Float32, reflect.Float64:\n    // ok, safe to call stats.Min\ndefault:\n    return fmt.Errorf(\"stats.Min requires numeric element type, got %v\", t)\n}","typeGuard":"func isMinSupportedNumber(v any) bool {\n    switch reflect.TypeOf(v).Kind() {\n    case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,\n        reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,\n        reflect.Float32, reflect.Float64:\n        return true\n    }\n    return false\n}","tryCatchPattern":null,"preventionTips":["Always map source data to float64/int64 before numeric aggregations.","Check your DoFn's output type annotation when changing element types.","Prefer transforms/top for non-numeric or custom ordering needs."],"tags":["go","apache-beam","panic","unsupported-type","stats"],"backgroundTag":"unsupported-dtype","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"}