apache/beam · error

Unexpected number type

Error message

Unexpected number type: %v

What it means

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.

Solutions

  1. 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.
  2. Convert non-numeric or decimal data to a supported numeric type before stats.Min, e.g. map to float64.
  3. For custom ordering semantics, use transforms/top (top.Smallest) with your own less function instead of stats.Min.

Example fix

// before
// stringCol: PCollection<string>
beam.ParDo(s, func(s string) string { return s }, stringCol)
stats.Min(s, stringCol) // panics: Unexpected number type: string

// after
numbers := beam.ParDo(s, func(s string) float64 {
    f, _ := strconv.ParseFloat(s, 64)
    return f
}, stringCol)
stats.Min(s, numbers)
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, safe to call stats.Min
default:
    return fmt.Errorf("stats.Min requires numeric element type, got %v", t)
}

Type guard

func isMinSupportedNumber(v any) bool {
    switch reflect.TypeOf(v).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:
        return true
    }
    return false
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/48b054ba3e955fc5. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/transforms/stats/min_switch.go:52

		return minInt32Fn
	case "int64":
		return minInt64Fn
	case "uint":
		return minUintFn
	case "uint8":
		return minUint8Fn
	case "uint16":
		return minUint16Fn
	case "uint32":
		return minUint32Fn
	case "uint64":
		return minUint64Fn
	case "float32":
		return minFloat32Fn
	case "float64":
		return minFloat64Fn
	default:
		panic(fmt.Sprintf("Unexpected number type: %v", t))
	}
}

func minIntFn(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func minInt8Fn(x, y int8) int8 {
	if x < y {
		return x
	}
	return y
}

func minInt16Fn(x, y int16) int16 {

View on GitHub (pinned to 12126d8942)