apache/beam · error

mismatched Flatten window types

Error message

mismatched Flatten window types: %v, want %v

What it means

NewFlatten verifies that all inputs use the same WindowingStrategy (compared with `w.Equals(n.WindowingStrategy())`, where w is derived from inputWindow(in)). If any input's windowing differs from the first input's, graph construction fails. Flatten requires homogeneous windowing because the merged output must carry a single strategy.

Solutions

  1. Apply the same beam.WindowInto to every input PCollection before flattening.
  2. Normalize trigger/lateness settings so all inputs' WindowingStrategies compare equal.
  3. Re-window all branches to a common windowing (e.g., GlobalWindows) before Flatten.
  4. Review which branch mutated windowing (window transforms, custom triggers) and align it.

Example fix

// before
merged := beam.Flatten(s, windowedPC, globalPC) // window strategy mismatch
// after
reWin := beam.WindowInto(s, window.NewFixedWindows(time.Hour), globalPC)
merged := beam.Flatten(s, windowedPC, reWin)
Defensive patterns

Strategy: validation

Validate before calling

// Go: apply identical windowing to all inputs before Flatten
winAll := func(pc beam.PCollection) beam.PCollection {
    return beam.WindowInto(s, window.NewFixedWindows(time.Hour), pc)
}
merged := beam.Flatten(s, winAll(a), winAll(b))

Prevention

When it happens

Trigger: Flattening PCollections where one has beam.WindowInto applied (fixed/sliding/session/global windows) and another keeps the default global window, or one has custom triggers/allowed lateness.

Common situations: Streaming pipelines where one branch is windowed for time-based aggregation and another is not; merging a re-windowed PCollection with the original; differing trigger configurations after GroupByKeys.

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

Appendix: source

Thrown at sdks/go/pkg/beam/core/graph/edge.go:278

	}
	t := in[0].Type()
	w := inputWindow(in)

	// TODO(herohde) 4/5/2018: is it fine mixing boundedness for flatten?
	// The output would be unbounded iff any input is.
	bounded := true
	for _, n := range in {
		if !n.Bounded() {
			bounded = false
			break
		}
	}
	for _, n := range in {
		if !typex.IsEqual(t, n.Type()) {
			return nil, addContext(errors.Errorf("mismatched Flatten input types: %v, want %v", n.Type(), t), s)
		}
		if !w.Equals(n.WindowingStrategy()) {
			return nil, addContext(errors.Errorf("mismatched Flatten window types: %v, want %v", n.WindowingStrategy(), w), s)
		}
	}
	if typex.IsCoGBK(t) {
		return nil, addContext(errors.Errorf("Flatten input type cannot be CoGBK: %v", t), s)
	}

	edge := g.NewEdge(s)
	edge.Op = Flatten
	for _, n := range in {
		edge.Input = append(edge.Input, &Inbound{Kind: Main, From: n, Type: t})
	}
	edge.Output = []*Outbound{{To: g.NewNode(t, w, bounded), Type: t}}
	return edge, nil
}

// NewCrossLanguage inserts a Cross-langugae External transform using initialized input and output nodes
func NewCrossLanguage(g *Graph, s *Scope, ext *ExternalTransform, ins []*Inbound, outs []*Outbound) (*MultiEdge, func(*Node, bool)) {
	edge := g.NewEdge(s)

View on GitHub (pinned to 12126d8942)