apache/beam · error
bad windowed value
Error message
bad windowed value: %v
What it means
EncodeCoderRef encodes coder.WindowedValue coders, which must have exactly one element component and a non-nil Window coder describing the windowing scheme. Anything else cannot be serialized into the runner form, so encoding fails with the coder printed in the message.
Solutions
- Ensure the WindowedValue coder has exactly one element component and a valid Window coder attached.
- Construct windowed coders via the SDK helpers that pair the element coder with the appropriate window coder.
- Check custom transforms that replace windowed coders and restore the Window field.
- Verify the windowing strategy (fixed/sliding/session/global) is initialized before the graph is serialized.
Example fix
// before
c := &coder.Coder{Kind: coder.WindowedValue, T: t, Components: []*coder.Coder{elm}} // Window nil
ref, err := graphx.EncodeCoderRef(c)
// after
c := &coder.Coder{Kind: coder.WindowedValue, T: t, Components: []*coder.Coder{elm}, Window: coder.NewIntervalWindowCoder()}
ref, err := graphx.EncodeCoderRef(c) Defensive patterns
Strategy: validation
Validate before calling
func validWindowed(c *coder.Coder) bool {
return c != nil && c.Kind == coder.WindowedValue && len(c.Components) == 1 && c.Window != nil
} Type guard
func hasWindow(c *coder.Coder) bool { return c != nil && c.Window != nil } Try / catch
ref, err := graphx.EncodeCoderRef(c)
if err != nil {
if strings.Contains(err.Error(), "bad windowed value") {
return fmt.Errorf("windowed coder needs 1 element component and a window coder: %w", err)
}
return err
} Prevention
- Attach the window coder whenever you wrap an element coder as windowed
- Never copy Coder structs field-by-field; deep-copy to keep Window
- Verify windowing is configured before pipeline submission
When it happens
Trigger: Encoding a coder.Coder of Kind coder.WindowedValue where len(c.Components) != 1 or c.Window == nil — e.g. a windowed coder assembled without attaching a window coder.
Common situations: Custom windowing code building WindowedValue coders without calling the window-coder constructor (e.g. coder.NewIntervalWindowCoder); global-window pipelines where the window field was cleared; copying coder structs and dropping the unexported/optional Window field.
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
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/68caee433b387aeb.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/core/runtime/graphx/dataflow.go:166
refs, err := EncodeCoderRefs(c.Components)
if err != nil {
return nil, err
}
value := refs[1]
if len(c.Components) > 2 {
// TODO(https://github.com/apache/beam/issues/18032): don't inject union coder for CoGBK.
union := &CoderRef{Type: cogbklistType, Components: refs[1:]}
value = &CoderRef{Type: lengthPrefixType, Components: []*CoderRef{union}}
}
stream := &CoderRef{Type: streamType, Components: []*CoderRef{value}, IsStreamLike: true}
return &CoderRef{Type: pairType, Components: []*CoderRef{refs[0], stream}, IsPairLike: true}, nil
case coder.WindowedValue:
if len(c.Components) != 1 || c.Window == nil {
return nil, errors.Errorf("bad windowed value: %v", c)
}
elm, err := EncodeCoderRef(c.Components[0])
if err != nil {
return nil, err
}
w, err := encodeWindowCoder(c.Window)
if err != nil {
return nil, err
}
return &CoderRef{Type: windowedValueType, Components: []*CoderRef{elm, w}, IsWrapper: true}, nil
case coder.IW:
return &CoderRef{Type: intervalWindowType}, nil
case coder.Bytes:
return &CoderRef{Type: bytesType}, nil
View on GitHub (pinned to 12126d8942)