apache/beam · error

not a float type: %v

Error message

not a float type: %v

What it means

NewFloat builds a custom 'float' coder for a Go type. It only supports reflect.Float32 and reflect.Float64; any other kind passed in produces this error. It is an upfront constructor validation, so it fails at coder-creation time, not during data processing.

Source

Thrown at sdks/go/pkg/beam/core/runtime/coderx/float.go:68

	n := math.Float64frombits(bits.ReverseBytes64(uval.(uint64)))
	switch t.Kind() {
	case reflect.Float64:
		return n, nil
	case reflect.Float32:
		return float32(n), nil
	default:
		panic(fmt.Sprintf("unreachable statement: expected a float, got %v", t))
	}
}

// NewFloat returns a coder for the given float type. It uses the same
// encoding scheme as the gob package.
func NewFloat(t reflect.Type) (*coder.CustomCoder, error) {
	switch t.Kind() {
	case reflect.Float32, reflect.Float64:
		return coder.NewCustomCoder("float", t, encFloat, decFloat)
	default:
		return nil, errors.Errorf("not a float type: %v", t)
	}
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Pass the actual float type: NewFloat(reflect.TypeOf(float64(0))).
  2. For named types like type Celsius float64, register a coder for the underlying kind or implement a custom coder.
  3. Check inferCoder inputs: ensure the schema element type is float32/float64 before selecting the float coder.

Example fix

// before
c, err := coderx.NewFloat(reflect.TypeOf(0))
// after
c, err := coderx.NewFloat(reflect.TypeOf(float64(0)))
Defensive patterns

Strategy: type-guard

Validate before calling

// guard before calling NewFloat
func canUseFloatCoder(t reflect.Type) bool {
    return t != nil && (t.Kind() == reflect.Float32 || t.Kind() == reflect.Float64)
}

Type guard

func isFloatKind(t reflect.Type) bool {
    switch t.Kind() {
    case reflect.Float32, reflect.Float64:
        return true
    }
    return false
}

Try / catch

c, err := coderx.NewFloat(t)
if err != nil {
    return fmt.Errorf("cannot build float coder for %s: %w", t, err)
}

Prevention

When it happens

Trigger: Calling coderx.NewFloat(t) with a non-float reflect.Type, e.g. NewFloat(reflect.TypeOf(0)) or a struct/slice type, often via inferCoder when a schema field's type isn't float.

Common situations: Registering coders for custom types that wrap a float (e.g. type Celsius float64) instead of the underlying float kind; typos in type registration.

Understand the failure class

Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.

Related errors


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