apache/beam · error

Unexpected number type

Error message

Unexpected number type: %v

What it means

In Apache Beam Go SDK's stats package, the min helpers dispatch to a numeric-specific min function via a generated switch on reflect.Type. When the element type is not one of the generated numeric instantiations, the default branch panics with 'Unexpected number type'. It enforces that Min is only applied to supported numeric PCollections.

Solutions

  1. Apply stats.Min only to PCollections of supported numeric element types.
  2. Insert beam.Map to convert elements to a supported numeric type before Min.
  3. Convert defined/aliased numeric types with an explicit cast DoFn to base types.
  4. Extend the template's type list and regenerate if a new numeric type is genuinely needed.

Example fix

// before
type Temp float64
stats.Min(s, temps) // panics for unregistered defined type

// after
raw := beam.Map(s, func(t Temp) float64 { return float64(t) }, temps)
stats.Min(s, raw)
Defensive patterns

Strategy: validation

Validate before calling

// Ensure Min input is a supported numeric type at graph construction
if !strings.Contains("|int|int8|int16|int32|int64|uint|uint8|uint16|uint32|uint64|float32|float64|", col.Type().String()+"|") {
    panic("stats.Min requires a supported numeric element type")
}

Type guard

func isMinSupported(v any) bool {
    switch reflect.ValueOf(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
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        if strings.Contains(fmt.Sprint(r), "Unexpected number type") {
            log.Printf("stats.Min called with unsupported element type: %v", r)
        }
        panic(r)
    }
}()

Prevention

When it happens

Trigger: Calling stats.Min on a PCollection whose element reflect.Type is not in the generated case list (string, struct, interface{}, bool, or an alias/defined type not covered).

Common situations: Accidentally applying Min to a string collection, defined types like type Celsius float64 whose reflect string doesn't match, or upstream transforms that erased concrete numeric types.

Related errors


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

Appendix: source

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

// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package stats

import (
    "fmt"
    "reflect"
)

func findMinFn(t reflect.Type) any {
    switch t.String() {
{{- range .X}}
    case "{{.Type}}":
		return min{{.Name}}Fn
{{- end}}
	default:
		panic(fmt.Sprintf("Unexpected number type: %v", t))
	}
}
{{range .X}}
func min{{.Name}}Fn(x, y {{.Type}}) {{.Type}} {
	if x < y {
		return x
	}
	return y
}
{{end}}

View on GitHub (pinned to 12126d8942)