{"record":{"id":"4c56e2d84516697c","repo":"apache/beam","slug":"invalid-to-nest-composite-inside-shardedkey-v-v","errorCode":null,"errorMessage":"Invalid to nest composite inside ShardedKey: %v, %v","messagePattern":"Invalid to nest composite inside ShardedKey: (.+?), (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/typex/fulltype.go","lineNumber":156,"sourceCode":"\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}\n}\n\n// NOTE(herohde) 1/26/2018: we allow nested KV types and coders to support the\n// CoGBK translation (using KV<K,KV<int,[]byte>> to encode keyed raw union values)\n// and potentially other uses. We do not have a reasonable way to emit nested KV\n// values, so user functions are still limited to non-nested KVs. Universally-typed\n// KV-values might be simple to allow, for example.\n\nfunc isAnyNonKVComposite(list []FullType) bool {\n\tfor _, t := range list {","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/typex/fulltype.go#L138-L174","documentation":"typex.New rejects ShardedKey types whose single component is itself a Composite (components[0].Class() == Composite). This panics with the type and components. The invariant is that a ShardedKey must wrap a concrete, non-composite type so its coder and shard-key extraction work directly.","triggerScenarios":"Calling typex.New(typex.ShardedKeyType, compositeType) where the single component's Class() is Composite, e.g. nesting a CoGBK or another composite inside ShardedKey, via New's public callers (Prefix, CoGroupByKey, CombinePerKey, CombineGlobally, Flatten, GroupByKey).","commonSituations":"Attempting to shard on a windowed or nested KV value; composing ShardedKey around a CoGBK type built for join translation; refactoring code that previously nested KV types (allowed) into ShardedKey (not allowed).","solutions":["Use a leaf type as the ShardedKey component instead of a composite.","If the value is logically a pair, encode it as a single concrete struct or as encoded []bytes rather than a typex composite.","Replace the nesting with an explicit outer KV: KV<K, ShardedKey<V>>."],"exampleFix":"// before\ntypex.New(typex.ShardedKeyType, typex.NewKV(k, v))\n// after\ntypex.New(typex.ShardedKeyType, vType)","handlingStrategy":"validation","validationCode":"func validShardedKeyComp(cs []typex.FullType) bool {\n    return len(cs) == 1 && cs[0] != nil && cs[0].Class() != typex.Composite\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":["Never nest a composite class directly inside ShardedKey.","Use KV<K, ShardedKey<V>> for keyed sharded data instead of nesting.","Check Class() before composing types programmatically."],"tags":["go","apache-beam","typex","panic","nested-composite"],"backgroundTag":"unsupported-operation","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"}