apache/beam · error

Invalid number of components for CoGBK

Error message

Invalid number of components for CoGBK: %v

What it means

FullType.New requires at least two components for a CoGBK composite (one key plus at least one value collection); fewer panics. CoGBK represents a keyed multi-input grouping type, so a component count below 2 cannot encode a grouping.

Solutions

  1. Provide at least a key and one value component when constructing a CoGBK type.
  2. For single-input grouping, use GroupByKey / GBKType instead of CoGBK.
  3. Validate the number of input PCollections before building the CoGBK type.

Example fix

// before
typex.New(typex.CoGBKType, keyFT) // 1 component: panics
// after
typex.New(typex.CoGBKType, keyFT, valFT1, valFT2)
Defensive patterns

Strategy: validation

Validate before calling

if t == typex.CoGBKType && len(components) < 2 {
	return fmt.Errorf("CoGBK requires at least 2 components, got %d", len(components))
}

Prevention

When it happens

Trigger: Calling typex.New (or CoGroupByKey / related graph helpers) with CoGBKType and a components slice of length 0 or 1, e.g. from a malformed transform input list.

Common situations: Custom graph builders passing an incomplete PCollection list to CoGroupByKey-shaped types; codegen emitting single-input CoGBK constructs instead of GBK.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at sdks/go/pkg/beam/core/typex/fulltype.go:143

		case KVType:
			if len(components) != 2 {
				panic(fmt.Sprintf("Invalid number of components for KV: %v, %v", t, components))
			}
			if isAnyNonKVAndNonWindowedComposite(components) {
				panic(fmt.Sprintf("Invalid to nest composite composites inside KV: %v, %v", t, components))
			}
			return &tree{class, t, components}
		case WindowedValueType:
			if len(components) != 1 {
				panic("Invalid number of components for WindowedValue")
			}
			if components[0].Type() == WindowedValueType {
				panic("Invalid to nest WindowedValue")
			}
			return &tree{class, t, components}
		case CoGBKType:
			if len(components) < 2 {
				panic(fmt.Sprintf("Invalid number of components for CoGBK: %v", t))
			}
			if isAnyNonKVComposite(components) {
				panic(fmt.Sprintf("Invalid to nest composites inside CoGBK: %v", t))
			}
			return &tree{class, t, components}
		case TimersType:
			return &tree{class, t, components}
		case ShardedKeyType:
			if len(components) != 1 {
				panic(fmt.Sprintf("Invalid number of components for ShardedKey: %v, %v", t, components))
			}
			if components[0].Class() == Composite {
				panic(fmt.Sprintf("Invalid to nest composite inside ShardedKey: %v, %v", t, components))
			}
			return &tree{class, t, components}
		default:
			panic(fmt.Sprintf("Unexpected composite type: %v", t))
		}

View on GitHub (pinned to 12126d8942)