{"record":{"id":"19c0bdb933772826","repo":"apache/beam","slug":"invalid-to-nest-composites-inside-cogbk-v","errorCode":null,"errorMessage":"Invalid to nest composites inside CoGBK: %v","messagePattern":"Invalid to nest composites inside CoGBK: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/typex/fulltype.go","lineNumber":146,"sourceCode":"\t\t\t}\n\t\t\tif isAnyNonKVAndNonWindowedComposite(components) {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid to nest composite composites inside KV: %v, %v\", t, components))\n\t\t\t}\n\t\t\treturn &tree{class, t, components}\n\t\tcase WindowedValueType:\n\t\t\tif len(components) != 1 {\n\t\t\t\tpanic(\"Invalid number of components for WindowedValue\")\n\t\t\t}\n\t\t\tif components[0].Type() == WindowedValueType {\n\t\t\t\tpanic(\"Invalid to nest WindowedValue\")\n\t\t\t}\n\t\t\treturn &tree{class, t, components}\n\t\tcase CoGBKType:\n\t\t\tif len(components) < 2 {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid number of components for CoGBK: %v\", t))\n\t\t\t}\n\t\t\tif isAnyNonKVComposite(components) {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid to nest composites inside CoGBK: %v\", t))\n\t\t\t}\n\t\t\treturn &tree{class, t, components}\n\t\tcase TimersType:\n\t\t\treturn &tree{class, t, components}\n\t\tcase ShardedKeyType:\n\t\t\tif len(components) != 1 {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid number of components for ShardedKey: %v, %v\", t, components))\n\t\t\t}\n\t\t\tif components[0].Class() == Composite {\n\t\t\t\tpanic(fmt.Sprintf(\"Invalid to nest composite inside ShardedKey: %v, %v\", t, components))\n\t\t\t}\n\t\t\treturn &tree{class, t, components}\n\t\tdefault:\n\t\t\tpanic(fmt.Sprintf(\"Unexpected composite type: %v\", t))\n\t\t}\n\tdefault:\n\t\tpanic(fmt.Sprintf(\"Invalid underlying type: %v\", t))\n\t}","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/typex/fulltype.go#L128-L164","documentation":"typex.New constructs the full-type tree and validates CoGBK types. A CoGBK type must have at least 2 components and every component must be a simple KV (or key-like) type; if isAnyNonKVComposite finds a non-KV composite among the components, New panics with this message. The Beam Go SDK intentionally forbids arbitrarily nested composite types inside CoGBK because its translation layer (CoGBK to GBK or union encodings) cannot represent them.","triggerScenarios":"Calling typex.New with a Composite type of class CoGBKType whose components include any non-KV composite, e.g. CoGBK<T1,WindowedValue<T2>> or CoGBK<KV<A,B>,T>. Reached via the public New constructor, which is invoked by beam type helpers such as CoGroupByKey, CombinePerKey, CombineGlobally, Flatten, GroupByKey and Prefix.","commonSituations":"Building custom PCollection coders/types for cross-bucket joins where a windowed or composite value type is passed as a CoGBK component; mixing typex.New(T, components...) manually with types that were legal in older Beam versions where nesting rules were looser.","solutions":["Flatten or restructure the composite components so each CoGBK component is a plain KV type (KV<K,V>).","If you truly need nesting, encode the nested value yourself, e.g. wrap it in a KV whose value is an encoded []byte, the pattern the SDK itself uses for CoGBK translation.","Check which helper (CoGroupByKey, CombinePerKey, etc.) supplied the offending type and pass a simpler typex.FullType instead."],"exampleFix":"// before\ntypex.New(typex.CoGBKType, kvType, windowedType)\n// after\ntypex.New(typex.CoGBKType, kvType, typex.NewKV(keyType, valueType))","handlingStrategy":"validation","validationCode":"func validCoGBKComponents(cs []typex.FullType) bool {\n    if len(cs) < 2 { return false }\n    for _, c := range cs {\n        if c == nil || (c.Class() == typex.Composite && c.Type() != typex.KVType) { return false }\n    }\n    return true\n}","typeGuard":null,"tryCatchPattern":"func safeNew(t typex.Type, cs ...typex.FullType) (ft typex.FullType, err error) {\n    defer func() {\n        if r := recover(); r != nil { err = fmt.Errorf(\"typex.New: %v\", r) }\n    }()\n    return typex.New(t, cs...), nil\n}","preventionTips":["Only pass plain KV components to CoGBK types.","Wrap nested values in encoded []byte form, as the SDK's own translation does.","Prefer beam's transform helpers (CoGroupByKey, CombinePerKey) over manual typex.New calls."],"tags":["go","apache-beam","typex","panic","type-validation"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}