apache/beam · error

got values, want one value for side input of type

Error message

got %d values, want one value for %v side input of type %v

What it means

For a Singleton side input, makeSideInput reads all buffered values and requires exactly one element, since a singleton (beam.AsSingleton) represents a single value. Receiving zero or multiple values means the producing PCollection did not yield exactly one element, so the library errors instead of guessing which value to use.

Solutions

  1. Reduce the side PCollection to exactly one element before viewing it as a singleton (e.g. beam.Combine, beam.First, beam.Count and assert == 1).
  2. If the PCollection may be empty, use beam.AsSingleton with a default: beam.AsSingleton(pcol, beam.SingletonDefault(v)).
  3. If multiple values are valid, switch the view type: beam.AsList (slice) or beam.AsMap/beam.AsMultiMap instead of beam.AsSingleton.

Example fix

// before: side may contain 0 or many elements
side := sfx components.Lookup(s, users)
out := beam.ParDo(s, &enrichFn{}, col, beam.SideInput{Input: beam.AsSingleton(s, side)})

// after: guarantee exactly one element with a combine
side := beam.Combine(s, func(a, b string) string { return a }, lookup)
out := beam.ParDo(s, &enrichFn{}, col, beam.SideInput{Input: beam.AsSingleton(s, side)})
Defensive patterns

Strategy: validation

Validate before calling

// before using beam.AsSingleton, guarantee exactly one element
combined := beam.Combine(s, func(a, b T) T { return a }, pcol)
// or provide a default:
// beam.AsSingleton(s, pcol, beam.SingletonDefault(defaultVal))

Prevention

When it happens

Trigger: makeSideInputs -> makeSideInput with a graph.Singleton view, where ReadAll(values) returns len(elms) != 1: an empty side-input PCollection, or a PCollection with 2+ elements used with beam.AsSingleton.

Common situations: Using beam.AsSingleton on a PCollection that can legitimately be empty (e.g. a filtered lookup that matched nothing) or has multiple rows; forgetting beam.CombinePerKey/beam.First to reduce the side PCollection to one element; driver code computing a default that produces more than one record.

Related errors


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

Appendix: source

Thrown at sdks/go/pkg/beam/core/runtime/exec/fn.go:516

	var ret []ReusableEmitter
	for i := 0; i < len(out); i++ {
		param := fn.Param[out[i]]
		ret = append(ret, makeEmit(param.T, nodes[i+offset]))
	}
	return ret, nil
}

// makeSideInput returns a reusable side input of the given kind and type.
func makeSideInput(kind graph.InputKind, t reflect.Type, values ReStream) (ReusableInput, error) {
	switch kind {
	case graph.Singleton:
		elms, err := ReadAll(values)
		if err != nil {
			return nil, err
		}
		if len(elms) != 1 {
			return nil, errors.Errorf("got %d values, want one value for %v side input of type %v", len(elms), graph.Singleton, t)
		}
		return &fixedValue{val: Convert(elms[0].Elm, t)}, nil

	case graph.Slice:
		elms, err := ReadAll(values)
		if err != nil {
			return nil, err
		}
		slice := reflect.MakeSlice(t, len(elms), len(elms))
		for i := 0; i < len(elms); i++ {
			slice.Index(i).Set(reflect.ValueOf(Convert(elms[i].Elm, t.Elem())))
		}
		return &fixedValue{val: slice.Interface()}, nil

	case graph.Iter:
		return makeIter(t, values), nil

	case graph.ReIter:

View on GitHub (pinned to 12126d8942)