apache/beam · error

unexpected number of parameters in method

Error message

unexpected number of parameters in method %v. got: %v, want: %v. Check that the signature conforms to the expected signature for %v, and that elements in SDF method parameters match elements in %v.

What it means

For a stateful SDF, InitialWatermarkEstimatorState must accept the same main-input elements that ProcessElement accepts, plus two extra parameters (event time and the restriction). Beam validates len(method.Param) == numMainIn + 2 and throws this error when the parameter count differs, since it cannot map the ProcessElement inputs onto the state-initialization call.

Solutions

  1. Give InitialWatermarkEstimatorState exactly the same main-input parameters as ProcessElement (same order), plus (typex.EventTime, restriction) appended.
  2. Count ProcessElement's main input parameters carefully (excluding context, watermark-estimator, event-time, and emit parameters) and match that count.
  3. Beam requires exact arity: remove extra parameters or add them to ProcessElement too.
  4. Compare against a working SDF example in the Beam repo for the same estimation style.

Example fix

// before (ProcessElement takes element; state initializer missing it)
func (f *fn) InitialWatermarkEstimatorState(rt typex.EventTime, rest MyRestriction) myState { return myState{} }
// after
func (f *fn) InitialWatermarkEstimatorState(element string, rt typex.EventTime, rest MyRestriction) myState {
    return myState{}
}
// matches: func (f *fn) ProcessElement(element string, wec sdf.WatermarkEstimator, emit func(string))
Defensive patterns

Strategy: validation

Validate before calling

// Arity check: main inputs of ProcessElement + 2
type pSig func(string, sdf.WatermarkEstimator, func(string))
type iwSig func(string, typex.EventTime, MyRestriction) myState
var _ = func() bool { var a pSig; var b iwSig; return a != nil && b != nil }

Prevention

When it happens

Trigger: InitialWatermarkEstimatorState declared with fewer parameters (e.g. just event time and restriction) or more parameters (extra context/options not in ProcessElement) than ProcessElement's main inputs + 2; ProcessElement's element set changed without updating InitialWatermarkEstimatorState.

Common situations: Adding a keyed or side-input parameter to ProcessElement without mirroring it in InitialWatermarkEstimatorState; trimming parameters for brevity; hand-writing the stateful method set with the wrong arity after copying a stateless SDF.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

	// If number of main inputs is ambiguous, we check for consistency against
	// CreateInitialRestriction.
	if numMainIn == int(MainUnknown) {
		initialRestFn := fn.methods[createInitialRestrictionName]
		paramNum := len(initialRestFn.Params(funcx.FnValue))

		switch paramNum {
		case int(MainSingle), int(MainKv):
			numMainIn = paramNum
		}
	}

	for _, name := range watermarkEstimationNames {
		method := fn.methods[name]
		switch name {
		case initialWatermarkEstimatorStateName:
			if len(method.Param) != numMainIn+2 {
				err := errors.Errorf("unexpected number of params in method %v. got: %v, want: %v",
					initialWatermarkEstimatorStateName, len(method.Param), numMainIn+2)
				return errors.SetTopLevelMsgf(err, "unexpected number of parameters in method %v. "+
					"got: %v, want: %v. Check that the signature conforms to the expected signature for %v, "+
					"and that elements in SDF method parameters match elements in %v.",
					initialWatermarkEstimatorStateName, len(method.Param), numMainIn+2, initialWatermarkEstimatorStateName, processElementName)
			}
			if method.Param[0].T != typex.EventTimeType {
				err := errors.Errorf("unexpected parameter type in method %v, param %v. got: %v, want: %v",
					initialWatermarkEstimatorStateName, 0, method.Param[0].T, typex.EventTimeType)
				return errors.SetTopLevelMsgf(err, "mismatched event time type in method %v, "+
					"parameter at index %v. got: %v, want: %v.",
					initialWatermarkEstimatorStateName, 0, method.Param[0].T, typex.EventTimeType)
			}
			if method.Param[1].T != restT {
				err := errors.Errorf("mismatched restriction type in method %v, param %v. got: %v, want: %v",
					initialWatermarkEstimatorStateName, 1, method.Param[1].T, restT)
				return errors.SetTopLevelMsgf(err, "mismatched restriction type in method %v, "+
					"parameter at index %v. got: %v, want: %v (from method %v). "+

View on GitHub (pinned to 12126d8942)