apache/beam · error

mismatched watermark state type in method

Error message

mismatched watermark state 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

WatermarkEstimatorState's sole parameter must be exactly the sdf.WatermarkEstimator interface type. Beam validates method.Param[0].T against watermarkEstimatorT and throws this error when the parameter is a different type, since it passes the constructed estimator to this method.

Solutions

  1. Change the parameter type to sdf.WatermarkEstimator and type-assert inside to your concrete estimator.
  2. Ensure CreateWatermarkEstimator returns a value assignable to sdf.WatermarkEstimator so the round trip type-checks.
  3. If you intended a state-parameter method, that's InitialWatermarkEstimatorState / CreateWatermarkEstimator — fix the method name instead.
  4. Follow the canonical stateful SDF example so all watermark method signatures stay consistent.

Example fix

// before
func (f *fn) WatermarkEstimatorState(st myState) myState { return st }
// after
func (f *fn) WatermarkEstimatorState(we sdf.WatermarkEstimator) myState {
    return we.(*myWatermarkEstimator).state
}
Defensive patterns

Strategy: type-guard

Validate before calling

var _ func(sdf.WatermarkEstimator) myState = (*fn).WatermarkEstimatorState

Type guard

func asWatermarkEstimator(v any) (sdf.WatermarkEstimator, bool) {
    we, ok := v.(sdf.WatermarkEstimator)
    return we, ok
}

Prevention

When it happens

Trigger: Declaring WatermarkEstimatorState(state myState) (reading state directly instead of the estimator); using a concrete estimator type or pointer where Beam expects the sdf.WatermarkEstimator interface parameter.

Common situations: Confusing the estimator object with the estimator state in the signature; writing the state-extraction method to take the state struct instead; following outdated or inconsistent examples.

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/e0e5d2e0a7913466. Report an issue: GitHub.

Appendix: source

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

			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)
				return errors.SetTopLevelMsgf(err, "mismatched watermark state 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.",
					watermarkEstimatorStateName, 0, method.Param[0].T, watermarkEstimatorT, watermarkEstimatorStateName)
			}
			if len(method.Ret) != 1 {
				err := errors.Errorf("unexpected number of elements returned in method %v. got: %v, want %v",
					watermarkEstimatorStateName, 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.",
					watermarkEstimatorStateName, len(method.Ret), 1, watermarkEstimatorStateName)
			}
			if method.Ret[0].T != watermarkStateT {
				err := errors.Errorf("mismatched output type in method %v, return %v. got: %v, want: %v",
					watermarkEstimatorStateName, 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). "+

View on GitHub (pinned to 12126d8942)