apache/beam · error

mismatched output type in method

Error message

mismatched output type in method %v, return value at index %v got: %v, want: %v (from method %v). Ensure that all watermark states in an SDF are the same type.

What it means

Within one stateful SDF, the watermark state type must be identical across methods. Beam validates that WatermarkEstimatorState's return type exactly equals the state type returned by CreateWatermarkEstimator; if they differ, validation fails with this error naming CreateWatermarkEstimator as the source of the expected type.

Solutions

  1. Make WatermarkEstimatorState return exactly the same type CreateWatermarkEstimator returns.
  2. If one method returns *myState and the other myState, unify on one form.
  3. Extract the state from the estimator consistently (e.g. a shared accessor returning the common type).
  4. Grep all watermark-state-related signatures in the DoFn and verify a single state type is used everywhere.

Example fix

// before
func (f *fn) CreateWatermarkEstimator(rest MyRestriction) *myEstimator { return &myEstimator{} }
func (f *fn) WatermarkEstimatorState(we sdf.WatermarkEstimator) myEstimator { ... }
// after
func (f *fn) CreateWatermarkEstimator(rest MyRestriction) *myEstimator { return &myEstimator{} }
func (f *fn) WatermarkEstimatorState(we sdf.WatermarkEstimator) *myEstimator {
    return we.(*myEstimator)
}
Defensive patterns

Strategy: validation

Validate before calling

var cwRet myEstimator = (*fn)(nil).CreateWatermarkEstimator(MyRestriction{}) // type must match WatermarkEstimatorState return
var _ func(sdf.WatermarkEstimator) myEstimator = (*fn).WatermarkEstimatorState

Prevention

When it happens

Trigger: WatermarkEstimatorState returns a different type than CreateWatermarkEstimator's return value — e.g. returning the state struct while CreateWatermarkEstimator returns an estimator wrapper, or a value vs pointer mismatch.

Common situations: Refactoring the state type in one method only; introducing a wrapper estimator type and updating only one signature; aliases or generics making types look identical but resolve differently.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


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

Appendix: source

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

					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). "+
					"Ensure that all restrictions in an SDF are the same type.",
					initialWatermarkEstimatorStateName, 1, method.Param[1].T, restT, createTrackerName)
			}
			if err := validateSdfElementT(fn, initialWatermarkEstimatorStateName, method, numMainIn, 2); err != nil {
				return err
			}

			if len(method.Ret) != 1 {
				err := errors.Errorf("unexpected number of elements returned in method %v. got: %v, want %v",
					initialWatermarkEstimatorStateName, len(method.Ret), 1)
				return errors.SetTopLevelMsgf(err, "unexpected number of elements returned in method %v. "+
					"got: %v, want %v. Check that the signature conforms to the expected signature for %v.",
					initialWatermarkEstimatorStateName, len(method.Ret), 1, initialWatermarkEstimatorStateName)
			}
			if method.Ret[0].T != watermarkStateT {
				err := errors.Errorf("mismatched output type in method %v, return %v. got: %v, want: %v",
					createWatermarkEstimatorName, 0, method.Ret[0].T, watermarkStateT)
				return errors.SetTopLevelMsgf(err, "mismatched output type in method %v, "+
					"return value at index %v got: %v, want: %v (from method %v). "+
					"Ensure that all watermark states in an SDF are the same type.",
					createWatermarkEstimatorName, 0, method.Ret[0].T, watermarkStateT, createWatermarkEstimatorName)
			}
		case watermarkEstimatorStateName:
			if len(method.Param) != 1 {
				err := errors.Errorf("unexpected number of params in method %v. got: %v, want %v",
					watermarkEstimatorStateName, len(method.Param), 1)
				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.",
					watermarkEstimatorStateName, len(method.Param), 1, watermarkEstimatorStateName, processElementName)
			}
			if method.Param[0].T != watermarkEstimatorT {
				err := errors.Errorf("mismatched watermark state type in method %v, return %v. got: %v, want: %v",
					watermarkEstimatorStateName, 0, method.Param[0].T, watermarkEstimatorT)

View on GitHub (pinned to 12126d8942)