apache/beam · error

Unexpected composite type

Error message

Unexpected composite type: %v

What it means

In typex.New's Composite branch, the switch over the type class only recognizes KV, CoGBK, WindowedValue, Timers and ShardedKey. Any other composite type class falls into the default case and panics with 'Unexpected composite type'. This guards against new or unknown composite classes reaching the tree builder without validation logic.

Solutions

  1. Use one of the supported composite classes (KV, CoGBK, WindowedValue, Timers, ShardedKey) when calling typex.New.
  2. Upgrade or align the Beam SDK versions in your module graph so type classes and validation agree (go mod tidy / go get -u sdks/go).
  3. If you added a custom composite class, add a case for it in New's switch in fulltype.go.
Defensive patterns

Strategy: validation

Validate before calling

var supportedComposites = map[typex.Type]bool{
    typex.KVType: true, typex.CoGBKType: true, typex.WindowedValueType: true,
    typex.TimersType: true, typex.ShardedKeyType: true,
}

Try / catch

func safeNew(t typex.Type, cs ...typex.FullType) (ft typex.FullType, err error) {
    defer func() {
        if r := recover(); r != nil { err = fmt.Errorf("typex.New: %v", r) }
    }()
    return typex.New(t, cs...), nil
}

Prevention

When it happens

Trigger: Calling typex.New with a Composite whose class is not one of KVType, CoGBKType, WindowedValueType, TimersType or ShardedKeyType — e.g. a custom or future typex class added upstream but not handled here. Reached via New's public callers (Prefix, CoGroupByKey, CombinePerKey, CombineGlobally, Flatten, GroupByKey).

Common situations: Using a Beam version where a new composite type class was introduced elsewhere but the fulltype validation wasn't updated; constructing composite types from raw class values programmatically instead of via the typed helpers.

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/77848e5971025003. Report an issue: GitHub.

Appendix: source

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

			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))
		}
	default:
		panic(fmt.Sprintf("Invalid underlying type: %v", t))
	}
}

// NOTE(herohde) 1/26/2018: we allow nested KV types and coders to support the
// CoGBK translation (using KV<K,KV<int,[]byte>> to encode keyed raw union values)
// and potentially other uses. We do not have a reasonable way to emit nested KV
// values, so user functions are still limited to non-nested KVs. Universally-typed
// KV-values might be simple to allow, for example.

func isAnyNonKVComposite(list []FullType) bool {
	for _, t := range list {
		if t.Class() == Composite && t.Type() != KVType {
			return true
		}
	}

View on GitHub (pinned to 12126d8942)