apache/beam · error

Unexpected window fn: %v

Error message

Unexpected window fn: %v

What it means

exec.assignWindows maps a window.WindowFn to its Go implementation (global, fixed, sliding, sessions, custom). Any windowfn type outside the handled cases has no assignment logic, so the library panics rather than silently mis-windowing elements.

Source

Thrown at sdks/go/pkg/beam/core/runtime/exec/window.go:86

		return []typex.Window{window.IntervalWindow{Start: start, End: end}}

	case window.SlidingWindows:
		var ret []typex.Window

		period := mtime.FromDuration(wfn.Period)
		lastStart := ts - (ts % period)
		for start := lastStart; start > ts.Subtract(wfn.Size); start -= period {
			ret = append(ret, window.IntervalWindow{Start: start, End: start.Add(wfn.Size)})
		}
		return ret
	case window.Sessions:
		// Assign each element into a window from its timestamp until Gap in the
		// future.  Overlapping windows (representing elements within Gap of
		// each other) will be merged.
		return []typex.Window{window.IntervalWindow{Start: ts, End: ts.Add(wfn.Gap)}}

	default:
		panic(fmt.Sprintf("Unexpected window fn: %v", wfn))
	}
}

func (w *WindowInto) FinishBundle(ctx context.Context) error {
	return w.Out.FinishBundle(ctx)
}

func (w *WindowInto) Down(ctx context.Context) error {
	return nil
}

func (w *WindowInto) String() string {
	return fmt.Sprintf("WindowInto[%v]. Out:%v", w.Fn, w.Out.ID())
}

// MapWindows maps each element window from a main input window space
// to window from a side input window space.
type MapWindows struct {

View on GitHub (pinned to 12126d8942)

Solutions

  1. Use window.NewGlobalWindows(), window.NewFixedWindows(...), window.NewSlidingWindows(...), or window.NewSessions(...) constructors
  2. If implementing a custom WindowFn, ensure it is registered and implements the expected window.WindowFn interface
  3. Check the pipeline payload/URN for window fn types not supported by the installed Beam Go SDK version

Example fix

// before
w := beam.WindowInto(scope, myUnknownWindower{}, col)
// after
w := beam.WindowInto(scope, window.NewFixedWindows(60*time.Second), col)
Defensive patterns

Strategy: validation

Validate before calling

switch wfn.(type) {
case window.GlobalWindows, window.FixedWindows, window.SlidingWindows, window.Sessions:
default:
    return fmt.Errorf("unsupported window fn: %T", wfn)
}

Try / catch

defer func() { if r := recover(); r != nil { err = fmt.Errorf("window assignment: %v", r) } }()

Prevention

When it happens

Trigger: Using a window.WindowFn value in a WindowInto transform (via assignWindows, called from ProcessElement or MapWindow) that is not one of: GlobalWindows, FixedWindows, SlidingWindows, Sessions, or a recognized custom fn.

Common situations: Passing a wrongly-typed value as a WindowFn (e.g. a trigger or a custom struct that isn't registered); deserializing a pipeline whose window fn URN is unknown to this SDK version.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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