{"record":{"id":"3afc7b19187f85da","repo":"apache/beam","slug":"got-d-values-want-one-value-for-v-side-input-of-type-v","errorCode":null,"errorMessage":"got %d values, want one value for %v side input of type %v","messagePattern":"got (.+?) values, want one value for (.+?) side input of type (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/exec/fn.go","lineNumber":516,"sourceCode":"\n\tvar ret []ReusableEmitter\n\tfor i := 0; i < len(out); i++ {\n\t\tparam := fn.Param[out[i]]\n\t\tret = append(ret, makeEmit(param.T, nodes[i+offset]))\n\t}\n\treturn ret, nil\n}\n\n// makeSideInput returns a reusable side input of the given kind and type.\nfunc makeSideInput(kind graph.InputKind, t reflect.Type, values ReStream) (ReusableInput, error) {\n\tswitch kind {\n\tcase graph.Singleton:\n\t\telms, err := ReadAll(values)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif len(elms) != 1 {\n\t\t\treturn nil, errors.Errorf(\"got %d values, want one value for %v side input of type %v\", len(elms), graph.Singleton, t)\n\t\t}\n\t\treturn &fixedValue{val: Convert(elms[0].Elm, t)}, nil\n\n\tcase graph.Slice:\n\t\telms, err := ReadAll(values)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tslice := reflect.MakeSlice(t, len(elms), len(elms))\n\t\tfor i := 0; i < len(elms); i++ {\n\t\t\tslice.Index(i).Set(reflect.ValueOf(Convert(elms[i].Elm, t.Elem())))\n\t\t}\n\t\treturn &fixedValue{val: slice.Interface()}, nil\n\n\tcase graph.Iter:\n\t\treturn makeIter(t, values), nil\n\n\tcase graph.ReIter:","sourceCodeStart":498,"sourceCodeEnd":534,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/fn.go#L498-L534","documentation":"For a Singleton side input, makeSideInput reads all buffered values and requires exactly one element, since a singleton (beam.AsSingleton) represents a single value. Receiving zero or multiple values means the producing PCollection did not yield exactly one element, so the library errors instead of guessing which value to use.","triggerScenarios":"makeSideInputs -> makeSideInput with a graph.Singleton view, where ReadAll(values) returns len(elms) != 1: an empty side-input PCollection, or a PCollection with 2+ elements used with beam.AsSingleton.","commonSituations":"Using beam.AsSingleton on a PCollection that can legitimately be empty (e.g. a filtered lookup that matched nothing) or has multiple rows; forgetting beam.CombinePerKey/beam.First to reduce the side PCollection to one element; driver code computing a default that produces more than one record.","solutions":["Reduce the side PCollection to exactly one element before viewing it as a singleton (e.g. beam.Combine, beam.First, beam.Count and assert == 1).","If the PCollection may be empty, use beam.AsSingleton with a default: beam.AsSingleton(pcol, beam.SingletonDefault(v)).","If multiple values are valid, switch the view type: beam.AsList (slice) or beam.AsMap/beam.AsMultiMap instead of beam.AsSingleton."],"exampleFix":"// before: side may contain 0 or many elements\nside := sfx components.Lookup(s, users)\nout := beam.ParDo(s, &enrichFn{}, col, beam.SideInput{Input: beam.AsSingleton(s, side)})\n\n// after: guarantee exactly one element with a combine\nside := beam.Combine(s, func(a, b string) string { return a }, lookup)\nout := beam.ParDo(s, &enrichFn{}, col, beam.SideInput{Input: beam.AsSingleton(s, side)})","handlingStrategy":"validation","validationCode":"// before using beam.AsSingleton, guarantee exactly one element\ncombined := beam.Combine(s, func(a, b T) T { return a }, pcol)\n// or provide a default:\n// beam.AsSingleton(s, pcol, beam.SingletonDefault(defaultVal))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call beam.AsSingleton on a PCollection that can be empty or multi-valued.","Reduce with beam.Combine or beam.First first.","Use beam.AsList/AsMap when multiple values are legitimate."],"tags":["go","apache-beam","side-input","singleton"],"backgroundTag":"unexpected-response-shape","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"}