apache/beam · error
Unexpected number type
Error message
Unexpected number type: %v
What it means
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.
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.
Example fix
// before max := stats.Max(s, strs) // strs is PCollection<string> // after nums := beam.ParDo(s, parseNum, strs) // map string -> float64 first max := stats.Max(s, nums)
Defensive patterns
Strategy: type-guard
Type guard
func isMaxSupported(v any) bool {
switch v.(type) {
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64:
return true
}
return false
}
// call before stats.Max: if !isMaxSupported(firstElem) { convert or use custom combine } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Accidentally feeding string or boolean collections into Max, type inference resolving to 'any'/interface after a refactor, or applying Max to encoded byte slices.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- pubsubio.Write only accepts PCollections of
- type must be a non-complex number
- Unexpected number type
- Unexpected number type
- AfterProcessingTime trigger set without a delay or…
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/f970e368237550a8.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/transforms/stats/max_switch.go:52
return maxInt32Fn
case "int64":
return maxInt64Fn
case "uint":
return maxUintFn
case "uint8":
return maxUint8Fn
case "uint16":
return maxUint16Fn
case "uint32":
return maxUint32Fn
case "uint64":
return maxUint64Fn
case "float32":
return maxFloat32Fn
case "float64":
return maxFloat64Fn
default:
panic(fmt.Sprintf("Unexpected number type: %v", t))
}
}
func maxIntFn(x, y int) int {
if x > y {
return x
}
return y
}
func maxInt8Fn(x, y int8) int8 {
if x > y {
return x
}
return y
}
func maxInt16Fn(x, y int16) int16 {View on GitHub (pinned to 12126d8942)