apache/beam · error

received unknown value type: want a number:, got %T

Error message

received unknown value type: want a number:, got %T

What it means

The deterministic hash for transform inputs only knows how to hash numeric types (ints, uints, floats) by converting them to uint64 bits. Any other value type reaching Hash hits the default case and panics. This is an internal type-support limitation of the hasher.

Source

Thrown at sdks/go/pkg/beam/core/runtime/exec/hash.go:166

		val = uint64(n)
	case int64:
		val = uint64(n)
	case uint:
		val = uint64(n)
	case uint8:
		val = uint64(n)
	case uint16:
		val = uint64(n)
	case uint32:
		val = uint64(n)
	case uint64:
		val = n
	case float64:
		val = math.Float64bits(n)
	case float32:
		val = uint64(math.Float64bits(float64(n)))
	default:
		panic(fmt.Sprintf("received unknown value type: want a number:, got %T", n))
	}
	binary.LittleEndian.PutUint64(h.cache, val)
	h.hash.Write(h.cache)
	h.we.EncodeSingle(w, h.hash)
	return h.hash.Sum64(), nil
}

type rowHasher struct {
	hash  hash.Hash64
	coder ElementEncoder
	we    WindowEncoder
	fv    FullValue
}

func (h *rowHasher) Hash(element any, w typex.Window) (uint64, error) {
	h.hash.Reset()
	h.fv.Elm = element
	if err := h.coder.Encode(&h.fv, h.hash); err != nil {

View on GitHub (pinned to 12126d8942)

Solutions

  1. Ensure only numeric types reach the hash path — convert/coerce the value to int64/uint64/float64 before hashing.
  2. If hashing custom structs, provide or use a coder path that hashes fields individually as numbers.
  3. Check whether an upstream conversion step was dropped, causing a raw value to be hashed.

Example fix

// before
Hash(v any) // panics when v is, e.g., a struct
// after
switch n := v.(type) {
case int64, uint64, float64:
	Hash(v)
default:
	// encode via type-specific hashing or reject earlier
}
Defensive patterns

Strategy: type-guard

Validate before calling

switch v.(type) {
case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64:
	// ok
default:
	return fmt.Errorf("cannot hash non-numeric value %T", v)
}

Type guard

func isHashableNumber(v any) bool {
	switch v.(type) {
	case int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64:
		return true
	}
	return false
}

Prevention

When it happens

Trigger: Hashing an element during potential-key re-hashing where the key component's dynamic type is not a numeric kind (e.g. a struct, string, or interface the switch doesn't handle) inside ProcessElement/Encode paths that use hash.go.

Common situations: Element coder/type changes so a non-number lands in the hash path; using custom types as elements that aren't reduced to plain numbers before hashing; Beam version differences in what gets hashed.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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