{"record":{"id":"248b7e28e580ccc8","repo":"apache/beam","slug":"need-at-least-1-pcollection","errorCode":null,"errorMessage":"need at least 1 pcollection","messagePattern":"need at least 1 pcollection","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/gbk.go","lineNumber":77,"sourceCode":"}\n\n// CoGroupByKey inserts a CoGBK transform into the pipeline.\nfunc CoGroupByKey(s Scope, cols ...PCollection) PCollection {\n\treturn Must(TryCoGroupByKey(s, cols...))\n}\n\nfunc addCoGBKCtx(err error, s Scope) error {\n\treturn errors.WithContextf(err, \"inserting CoGroupByKey in scope %s\", s)\n}\n\n// TryCoGroupByKey inserts a CoGBK transform into the pipeline. Returns\n// an error on failure.\nfunc TryCoGroupByKey(s Scope, cols ...PCollection) (PCollection, error) {\n\tif !s.IsValid() {\n\t\treturn PCollection{}, addCoGBKCtx(errors.New(\"invalid scope\"), s)\n\t}\n\tif len(cols) < 1 {\n\t\treturn PCollection{}, addCoGBKCtx(errors.New(\"need at least 1 pcollection\"), s)\n\t}\n\tfor i, in := range cols {\n\t\tif !in.IsValid() {\n\t\t\treturn PCollection{}, addCoGBKCtx(errors.Errorf(\"invalid pcollection to CoGBK: index %v\", i), s)\n\t\t}\n\t}\n\n\tvar in []*graph.Node\n\tfor _, s := range cols {\n\t\tin = append(in, s.n)\n\t}\n\n\tedge, err := graph.NewCoGBK(s.real, s.scope, in)\n\tif err != nil {\n\t\treturn PCollection{}, err\n\t}\n\tret := PCollection{edge.Output[0].To}\n\tret.SetCoder(NewCoder(ret.Type()))","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/gbk.go#L59-L95","documentation":"TryCoGroupByKey needs at least one PCollection to co-group; with zero inputs the CoGBK transform has nothing to work on, so the library returns this error with context about the scope. Valid collections are then additionally checked individually.","triggerScenarios":"beam.CoGroupByKey(s) or beam.TryCoGroupByKey(s) called with an empty variadic list, typically when collections are accumulated dynamically (map/slice iteration) and the container is empty.","commonSituations":"Aggregating inputs from a config-driven list of sources that resolved to nothing; conditional pipeline construction where all candidate branches were omitted; passing an empty slice with '...' expansion.","solutions":["Guard: if len(cols) == 0 skip the CoGroupByKey call or return a descriptive error from your own code.","Ensure at least one input PCollection is produced upstream before grouping.","Log the number of candidate collections just before the call to locate where they were dropped."],"exampleFix":"// before\ngrouped := beam.CoGroupByKey(s, cols...) // errors when len(cols)==0\n\n// after\nif len(cols) == 0 {\n\treturn fmt.Errorf(\"no inputs to CoGroupByKey\")\n}\ngrouped := beam.CoGroupByKey(s, cols...)","handlingStrategy":"validation","validationCode":"if len(cols) < 1 {\n\treturn fmt.Errorf(\"CoGroupByKey requires at least one pcollection\")\n}\nout := beam.CoGroupByKey(s, cols...)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Assert at least one input collection exists before variadic expansion.","When collections come from config, validate the config list is non-empty at startup.","Log candidate collection counts when building groups dynamically."],"tags":["go","apache-beam","cogroupbykey","empty-input"],"backgroundTag":"missing-required-argument","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}