apache/beam · error
Unexpected number type
Error message
Unexpected number type: %v
What it means
stats.Sum selects a per-type summation function via a switch on the element type's kind (sumIntFn, sumUint64Fn, sumFloat32Fn, sumFloat64Fn, etc.). If the element type is not one of the supported numeric kinds, findSumFn panics with 'Unexpected number type'. Only Go fixed numeric types can be summed by this transform.
Solutions
- Verify the element type is a supported numeric kind (int*/uint*/float32/float64) before calling stats.Sum.
- Convert the data with a ParDo/Map to float64 or int64 prior to summing.
- For complex or decimal types, implement a custom beam.Combine combine function instead of stats.Sum.
Example fix
// before
stats.Sum(s, recordCol) // recordCol is a struct -> panics
// after
values := beam.ParDo(s, func(r Record) float64 { return r.Amount }, recordCol)
stats.Sum(s, values) Defensive patterns
Strategy: validation
Validate before calling
t := reflect.TypeOf(el)
switch t.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
reflect.Float32, reflect.Float64:
// ok
default:
return fmt.Errorf("stats.Sum requires numeric element type, got %v", t)
} Type guard
func isSummable(v any) bool {
k := reflect.TypeOf(v).Kind()
return k >= reflect.Int && k <= reflect.Float64 && k != reflect.Uintptr
} Prevention
- Convert strings/decimals to float64 in an upstream ParDo before summing.
- Avoid passing record structs directly to Sum; extract the numeric field first.
- Keep a unit test asserting the PCollection coder type before aggregation.
When it happens
Trigger: Calling stats.Sum(s, col) or SumPerKey on a PCollection whose element reflect.Kind is not in the switch (string, bool, struct, slice, uintptr, complex, etc.).
Common situations: Summing a string-encoded number without conversion; accidentally summing a struct/record column; using complex128 data; a custom named type whose kind maps to an unsupported case.
Related errors
- Unexpected number type
- type must be a non-complex number
- Unexpected number type
- AfterProcessingTime trigger set without a delay or…
- At least one subtrigger required for composite triggers.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/869064ebae56e2c4.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/transforms/stats/sum_switch.go:52
return sumInt32Fn
case "int64":
return sumInt64Fn
case "uint":
return sumUintFn
case "uint8":
return sumUint8Fn
case "uint16":
return sumUint16Fn
case "uint32":
return sumUint32Fn
case "uint64":
return sumUint64Fn
case "float32":
return sumFloat32Fn
case "float64":
return sumFloat64Fn
default:
panic(fmt.Sprintf("Unexpected number type: %v", t))
}
}
func sumIntFn(x, y int) int {
return x + y
}
func sumInt8Fn(x, y int8) int8 {
return x + y
}
func sumInt16Fn(x, y int16) int16 {
return x + y
}
func sumInt32Fn(x, y int32) int32 {
return x + y
}View on GitHub (pinned to 12126d8942)