apache/beam · error

batch: unknown sizer kind

Error message

batch: unknown sizer kind %d

What it means

sizeOf falls through to its default branch when the configured sizer kind is not one of sizerNone/sizerPrimitive/sizerCustom. This is an internal invariant: the Sizer enum field was set to an undefined value, so the transform cannot dispatch and panics.

Solutions

  1. Use only the exported sizer constants (sizerNone/sizerPrimitive/sizerCustom equivalents) when constructing the DoFn.
  2. Add validation at DoFn construction time to reject unknown sizer kinds early.
  3. Update to the latest SDK where the sizer API may be typed to prevent invalid values.
  4. Audit code that sets the sizer field numerically and replace with named constants.

Example fix

// before
fn := batchFn[K, V]{Sizer: 7}
// after
fn := batchFn[K, V]{Sizer: sizerPrimitive}
Defensive patterns

Strategy: validation

Validate before calling

// Validate the sizer kind before constructing the DoFn
func validSizer(k int32) bool {
	return k == sizerNone || k == sizerPrimitive || k == sizerCustom
}
if !validSizer(mySizerKind) {
	panic(fmt.Sprintf("invalid sizer kind %d", mySizerKind))
}

Prevention

When it happens

Trigger: Constructing the batch DoFn with a Sizer field set to an out-of-range integer (not one of the exported sizer* constants) and then processing elements via ProcessElement.

Common situations: Hand-rolled struct literals copying examples with a numeric Sizer field, or upstream code changes that renumbered the sizer constants.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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

Appendix: source

Thrown at sdks/go/pkg/beam/transforms/batch/batch.go:482

	if setBool {
		fn.Buffering.Clear(tp)
		if err := fn.TimerSet.Clear(sp); err != nil {
			panic(err)
		}
	}
}

func sizeOf(kind int32, v any) int64 {
	switch kind {
	case sizerNone:
		return 0
	case sizerPrimitive:
		if size, ok := defaultElementByteSize(v); ok {
			return size
		}
		panic(fmt.Sprintf("batch: sizerPrimitive cannot size value of type %T", v))
	default:
		panic(fmt.Sprintf("batch: unknown sizer kind %d", kind))
	}
}

// wrapShardedKeyFn maps KV<K, V> → KV<ShardedKey[K], V>.
type wrapShardedKeyFn[K any] struct{}

func (*wrapShardedKeyFn[K]) ProcessElement(
	key K, value typex.V, emit func(ShardedKey[K], typex.V),
) {
	emit(ShardedKey[K]{Key: key, ShardID: makeShardID()}, value)
}

var (
	workerUUIDOnce sync.Once
	workerUUIDVal  [16]byte
	shardCounter   atomic.Uint64
)

View on GitHub (pinned to 12126d8942)