apache/beam · error

number of side inputs in method %v does not match method %v:

Error message

number of side inputs in method %v does not match method %v: got %d, expected %d

What it means

validateSideInputs requires a DoFn auxiliary method's input count (after main inputs) to equal the number of side inputs in ProcessElement. This error is thrown from AsDoFn when the auxiliary method declares a different number of side-input parameters than ProcessElement provides.

Source

Thrown at sdks/go/pkg/beam/core/graph/fn.go:766

	numSideIn := numProcessIn - int(numMainIn)
	posMethodIn, numMethodIn, ok := method.Inputs()

	// Handle cases where method has no inputs.
	if !ok {
		if numSideIn == 0 { // We're good, expected no side inputs.
			return nil
		}
		// Error, missing side inputs.
		err := errors.Errorf("side inputs expected in method %v", methodName)
		return errors.SetTopLevelMsgf(err,
			"Missing side inputs in the %v method of a DoFn. "+
				"If side inputs are present in %v those side inputs must also be present in %v.",
			methodName, processElementName, methodName)
	}

	// Error if number of side inputs doesn't match.
	if numMethodIn != numSideIn {
		err := errors.Errorf("number of side inputs in method %v does not match method %v: got %d, expected %d",
			methodName, processElementName, numMethodIn, numSideIn)
		return errors.SetTopLevelMsgf(err,
			"Incorrect number of side inputs in the %v method of a DoFn. "+
				"The side inputs should match those of the %v method.",
			methodName, processElementName)
	}

	// Error if there's a type mismatch.
	methodInputs := method.Param[posMethodIn : posMethodIn+numMethodIn]
	sideInputs := processFnInputs[numMainIn:] // Skip main inputs in ProcessFn
	for i := 0; i < len(sideInputs); i++ {
		if sideInputs[i].T != methodInputs[i].T {
			var err error = &funcx.TypeMismatchError{Got: methodInputs[i].T, Want: sideInputs[i].T}
			err = errors.Wrapf(err, "side input in method %v does not match side input in %v",
				methodName, processElementName)
			return errors.SetTopLevelMsgf(err,
				"Incorrect side inputs in the %v method of a DoFn. "+
					"The side inputs should match those of the %v method.",

View on GitHub (pinned to 12126d8942)

Solutions

  1. Align the auxiliary method's side input parameter count with ProcessElement's side inputs.
  2. Update the beam.ParDo call to pass exactly the number of side inputs the DoFn methods declare.
  3. Keep types aligned too, otherwise error 4904 follows.

Example fix

// before
func (fn *myFn) ProcessElement(w string, a beam.V, b beam.V) {}
func (fn *myFn) StartBundle(a beam.V) {}

// after
func (fn *myFn) ProcessElement(w string, a beam.V, b beam.V) {}
func (fn *myFn) StartBundle(a beam.V, b beam.V) {}
Defensive patterns

Strategy: validation

Validate before calling

// verify side input count parity before building:
if numSideInputsInParDo != countSideInputParams(doFnMethods) {
	return fmt.Errorf("side input count mismatch")
}

Type guard

func countSideInputParams(m reflect.Method) int { return m.Type.NumIn() - baseParams(m) }

Try / catch

err := beam.ParDo(s, fn, in, beam.SideInput{...}); if err != nil { log.Fatalf("side input mismatch: %v", err) }

Prevention

When it happens

Trigger: A StartBundle/FinishBundle method declaring fewer or more side input parameters than the beam.ParDo call supplies (e.g. one side input at the call site, two in the method), during AsDoFn conversion.

Common situations: Adding another beam.SideInput to the ParDo call without updating DoFn methods; removing a side input from ProcessElement but leaving it in FinishBundle; count mismatch after refactoring multi-input transforms.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


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