{"record":{"id":"9bf9c263780ce9b5","repo":"apache/beam","slug":"flatten-input-type-cannot-be-cogbk-v","errorCode":null,"errorMessage":"Flatten input type cannot be CoGBK: %v","messagePattern":"Flatten input type cannot be CoGBK: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/graph/edge.go","lineNumber":282,"sourceCode":"\t// TODO(herohde) 4/5/2018: is it fine mixing boundedness for flatten?\n\t// The output would be unbounded iff any input is.\n\tbounded := true\n\tfor _, n := range in {\n\t\tif !n.Bounded() {\n\t\t\tbounded = false\n\t\t\tbreak\n\t\t}\n\t}\n\tfor _, n := range in {\n\t\tif !typex.IsEqual(t, n.Type()) {\n\t\t\treturn nil, addContext(errors.Errorf(\"mismatched Flatten input types: %v, want %v\", n.Type(), t), s)\n\t\t}\n\t\tif !w.Equals(n.WindowingStrategy()) {\n\t\t\treturn nil, addContext(errors.Errorf(\"mismatched Flatten window types: %v, want %v\", n.WindowingStrategy(), w), s)\n\t\t}\n\t}\n\tif typex.IsCoGBK(t) {\n\t\treturn nil, addContext(errors.Errorf(\"Flatten input type cannot be CoGBK: %v\", t), s)\n\t}\n\n\tedge := g.NewEdge(s)\n\tedge.Op = Flatten\n\tfor _, n := range in {\n\t\tedge.Input = append(edge.Input, &Inbound{Kind: Main, From: n, Type: t})\n\t}\n\tedge.Output = []*Outbound{{To: g.NewNode(t, w, bounded), Type: t}}\n\treturn edge, nil\n}\n\n// NewCrossLanguage inserts a Cross-langugae External transform using initialized input and output nodes\nfunc NewCrossLanguage(g *Graph, s *Scope, ext *ExternalTransform, ins []*Inbound, outs []*Outbound) (*MultiEdge, func(*Node, bool)) {\n\tedge := g.NewEdge(s)\n\tedge.Op = External\n\tedge.External = ext\n\n\tws := window.DefaultWindowingStrategy()","sourceCodeStart":264,"sourceCodeEnd":300,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/graph/edge.go#L264-L300","documentation":"After the type/window checks, NewFlatten rejects any input whose type is a CoGBK type (`typex.IsCoGBK`). CoGBK represents an unexploded multi-input grouping result, which Flatten cannot merge as a regular element stream. The graph builder throws this to prevent flattening grouped/deferred multi-input values.","triggerScenarios":"Passing the output of beam.CoGroupByKey (or a PCollection typed as CoGBK) directly into beam.Flatten.","commonSituations":"Trying to merge results of multiple CoGroupByKey operations; misunderstanding CoGBK outputs as ordinary PCollections and passing them to combinators that only accept main inputs.","solutions":["Expand the CoGBK result first: use beam.ParDo with a func over the CoGBK KV to emit per-key records, then flatten.","Merge the pre-CoGBK inputs (flatten before grouping) if the intent is to group them together.","Use beam.Explode (or a custom expansion DoFn) on each CoGBK collection prior to Flatten.","Restructure so Flatten operates on plain typed PCollections only."],"exampleFix":"// before\nmerged := beam.Flatten(s, cogbk1, cogbk2) // CoGBK inputs rejected\n// after\nexpand := func(k beam.KV, it func(*string) bool) string { /* emit value */ return \"\" }\nflat1 := beam.ParDo(s, expand, cogbk1)\nflat2 := beam.ParDo(s, expand, cogbk2)\nmerged := beam.Flatten(s, flat1, flat2)","handlingStrategy":"validation","validationCode":"// Go: expand CoGBK outputs before Flatten\nexpand := func(kv beam.KV, iter func(*T) bool) T { var v T; iter(&v); return v }\nflattenable := beam.ParDo(s, expand, cogbkPC)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat CoGBK outputs as grouped multi-input values, never as flattenable elements.","Explode/expand grouped results before any downstream element-wise combinator.","Flatten inputs before grouping when the goal is a combined group."],"tags":["beam-go","flatten","cogbk","unsupported-type"],"backgroundTag":"incompatible-source-type","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"}