apache/beam · error

no input pcollections

Error message

no input pcollections

What it means

TryFlatten requires at least one input PCollection to merge; calling it with zero PCollections makes the flatten transform meaningless (nothing to produce), so the library rejects the call with this error. Note the check runs after the per-collection validity loop, so collections must also be valid.

Source

Thrown at sdks/go/pkg/beam/flatten.go:47

// of the first PCollection.
func Flatten(s Scope, cols ...PCollection) PCollection {
	return Must(TryFlatten(s, cols...))
}

// TryFlatten merges incoming PCollections of type 'A' to a single PCollection
// of type 'A'. Returns an error indicating the set of PCollections that could
// not be flattened.
func TryFlatten(s Scope, cols ...PCollection) (PCollection, error) {
	if !s.IsValid() {
		return PCollection{}, errors.New("invalid scope")
	}
	for i, in := range cols {
		if !in.IsValid() {
			return PCollection{}, errors.Errorf("invalid pcollection to flatten: index %v", i)
		}
	}
	if len(cols) == 0 {
		return PCollection{}, errors.New("no input pcollections")
	}
	if len(cols) == 1 {
		return cols[0], nil // no-op
	}

	var in []*graph.Node
	for _, s := range cols {
		in = append(in, s.n)
	}
	edge, err := graph.NewFlatten(s.real, s.scope, in)
	if err != nil {
		return PCollection{}, err
	}
	ret := PCollection{edge.Output[0].To}
	ret.SetCoder(cols[0].Coder())
	return ret, nil
}

View on GitHub (pinned to 12126d8942)

Solutions

  1. Guard the call: only invoke Flatten when len(cols) > 0; if the slice is empty, skip the flatten and use/propagate the (empty) inputs appropriately.
  2. If logically there is exactly one input, call it directly — TryFlatten already no-ops for len==1, so a single element is fine, zero is not.
  3. Log the input collection list before the call to find why all candidates were filtered out.

Example fix

// before
merged := beam.Flatten(s, cols...) // panics/errors when cols is empty

// after
var merged beam.PCollection
switch {
case len(cols) == 0:
	// handle empty case, e.g. skip flatten or return an error
default:
	merged = beam.Flatten(s, cols...)
}
Defensive patterns

Strategy: validation

Validate before calling

if len(cols) == 0 {
	return fmt.Errorf("no pcollections to flatten")
}
out := beam.Flatten(s, cols...)

Prevention

When it happens

Trigger: beam.Flatten(s) or beam.TryFlatten(s) called with an empty variadic list — typically when the inputs are gathered programmatically (e.g. appending to a slice under conditions that all evaluated false) and the slice is empty at call time.

Common situations: Building a list of PCollections from optional/conditional pipeline branches where every branch was skipped; refactoring that removed all inputs but kept the Flatten call; passing a filtered slice without checking its length.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


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