{"record":{"id":"282b3f7f503542a9","repo":"apache/beam","slug":"top-accum-element-encoder-unspecified-with-non-zero-elements","errorCode":null,"errorMessage":"top.accum: element encoder unspecified with non-zero elements: %v data available","messagePattern":"top\\.accum: element encoder unspecified with non-zero elements: (.+?) data available","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/transforms/top/top.go","lineNumber":158,"sourceCode":"}\n\nvar (\n\taccumType = reflect.TypeOf((*accum)(nil)).Elem()\n)\n\nfunc init() {\n\tbeam.RegisterType(accumType)\n\tbeam.RegisterCoder(accumType, accumEnc(), accumDec())\n}\n\nfunc accumEnc() func(accum) ([]byte, error) {\n\tbyteEnc, err := coder.EncoderForSlice(reflect.TypeOf((*[][]byte)(nil)).Elem())\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\treturn func(a accum) ([]byte, error) {\n\t\tif len(a.list) > 0 && a.enc == nil {\n\t\t\treturn nil, errors.Errorf(\"top.accum: element encoder unspecified with non-zero elements: %v data available\", len(a.data))\n\t\t}\n\t\tvar values [][]byte\n\t\tif len(a.list) == 0 && len(a.data) > 0 {\n\t\t\tvalues = a.data\n\t\t}\n\t\tfor _, value := range a.list {\n\t\t\tvar buf bytes.Buffer\n\t\t\tif err := a.enc.Encode(value, &buf); err != nil {\n\t\t\t\treturn nil, errors.WithContextf(err, \"top.accum: marshalling %v\", value)\n\t\t\t}\n\t\t\tvalues = append(values, buf.Bytes())\n\t\t}\n\n\t\tvar buf bytes.Buffer\n\t\tif err := coder.WriteSimpleRowHeader(1, &buf); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif err := byteEnc(values, &buf); err != nil {","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/transforms/top/top.go#L140-L176","documentation":"In Beam's top transform, the accum (accumulator for CombineFn) holds decoded elements plus buffered raw data and an optional element coder. This error is raised by the accumulator encoding function when the accumulator has decoded elements in its list but no encoder is set, making it impossible to serialize the accum (e.g. forGBK state or shuffle). It's an internal invariant violation: an enc-less accum should never hold non-empty list elements.","triggerScenarios":"Combining with the top transform where the element coder is unspecified/nil (e.g. coder couldn't be inferred) while the accumulator already carries decoded elements during merge/extract of an accum that has both list and data populated.","commonSituations":"Pipeline uses transforms/top with a coder Beam could not infer (custom types without registered coders), or accumulation data flows across worker boundaries requiring serialization of an improperly initialized accum.","solutions":["Ensure the element type has a registered/inferable Beam coder (implement Coder interfaces or register external coder)","Check that the PCollection fed to Top has a non-nil element coder","Update Beam SDK version; older versions had top coder-inference bugs","If reproducible, file/report with the pipeline graph since this is an internal invariant violation"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"pc := beam.ParDo(s, fn, input)\nif pc.Coder() == nil {\n\treturn fmt.Errorf(\"element coder missing for Top input\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use types with registered Beam coders for Top inputs","Keep SDK versions current for coder-inference fixes","Don't mix raw buffered data and decoded elements in custom combines"],"tags":["apache-beam","coder","internal","top-transform"],"backgroundTag":"internal-invariant-violation","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"}