apache/beam · error
RestrictionSize has unexpected number of parameters: %v
Error message
RestrictionSize has unexpected number of parameters: %v
What it means
The RestrictionSize function of an SDF must take between 2 and 4 parameters (restriction plus element/timestamp inputs) and return a float64. initCallFn rejects other arities with this error during invoker setup, since sizing needs the restriction and its inputs to compute a size.
Source
Thrown at sdks/go/pkg/beam/core/runtime/exec/sdf_invokers_arity.go:202
r0, r1 := fnT.Call2x2(n.args[0], n.args[1])
return r0.(float64), asError(r1)
}
case reflectx.Func3x2:
n.call = func() (size float64, err error) {
r0, r1 := fnT.Call3x2(n.args[0], n.args[1], n.args[2])
return r0.(float64), asError(r1)
}
case reflectx.Func4x2:
n.call = func() (size float64, err error) {
r0, r1 := fnT.Call4x2(n.args[0], n.args[1], n.args[2], n.args[3])
return r0.(float64), asError(r1)
}
default:
if len(n.fn.Param) < 2 || len(n.fn.Param) > 4 {
return errors.Errorf("RestrictionSize has unexpected number of parameters: %v", len(n.fn.Param))
}
n.call = func() (size float64, err error) {
ret := n.fn.Fn.Call(n.args)
switch len(ret) {
case 1:
return ret[0].(float64), nil
case 2:
return ret[0].(float64), asError(ret[1])
}
panic(fmt.Sprintf("RestrictionSize has unexpected number of return values: %v", len(ret)))
}
}
return nil
}View on GitHub (pinned to 12126d8942)
Solutions
- Give RestrictionSize 2-4 parameters, e.g. func(el T, rest R) float64.
- Ensure the signature mirrors SplitRestriction's parameter shape so both validate.
- Remove or add parameters to fall within the 2-4 arity range.
- Consult the sdf package size-function examples when in doubt.
Example fix
// before
func (fn *mySdf) RestrictionSize(rest watermarksInterval) float64 { ... }
// after
func (fn *mySdf) RestrictionSize(el string, rest watermarksInterval) float64 { ... } Defensive patterns
Strategy: validation
Validate before calling
t := reflect.TypeOf(fn.RestrictionSize)
n := t.NumIn()
if n < 2 || n > 4 {
return fmt.Errorf("RestrictionSize must take 2-4 parameters, has %d", n)
} Try / catch
if err != nil {
if strings.Contains(err.Error(), "RestrictionSize has unexpected number of parameters") {
// fix arity to 2-4
}
return err
} Prevention
- Use func(el T, rest R) float64 as the canonical size signature.
- Keep size/split signatures consistent with each other.
- Confirm the function returns float64, not int.
When it happens
Trigger: Registering a RestrictionSize fn with fewer than 2 parameters (e.g. only the restriction) or more than 4, hitting the default validation at sdf_invokers_arity.go:202 when the fast paths don't match.
Common situations: Writing a size function taking only the restriction for simplicity, or mirroring a different SDK's signature; also occurs when the tracker parameter is mistakenly included/omitted relative to the supported forms.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- CreateWatermarkEstimator fn %v has unexpected number of para
- InitialWatermarkEstimatorState fn %v has unexpected number o
- WatermarkEstimatorState fn %v has unexpected number of param
- CreateInitialRestriction has unexpected number of parameters
- SplitRestriction has unexpected number of parameters: %v
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/6d3c869c37b91a25.
Report an issue: GitHub.