{"record":{"id":"97383d3095f8199f","repo":"apache/beam","slug":"pcollection-is-empty-want-non-empty-collection","errorCode":null,"errorMessage":"PCollection is empty, want non-empty collection","messagePattern":"PCollection is empty, want non-empty collection","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/passert/passert.go","lineNumber":194,"sourceCode":"\treturn errors.Errorf(f.Format, fmt.Sprintf(\"(%v,%v)\", x, y))\n}\n\ntype failGBKFn struct {\n\tFormat string `json:\"format\"`\n}\n\nfunc (f *failGBKFn) ProcessElement(x beam.X, _ func(*beam.Y) bool) error {\n\treturn errors.Errorf(f.Format, fmt.Sprintf(\"(%v,*)\", x))\n}\n\ntype nonEmptyFn struct{}\n\nfunc (n *nonEmptyFn) ProcessElement(_ []byte, iter func(*beam.Z) bool) error {\n\tvar val beam.Z\n\tfor iter(&val) {\n\t\treturn nil\n\t}\n\treturn errors.New(\"PCollection is empty, want non-empty collection\")\n}\n\n// NonEmpty asserts that the given PCollection has at least one element.\nfunc NonEmpty(s beam.Scope, col beam.PCollection) beam.PCollection {\n\ts = s.Scope(\"passert.NonEmpty\")\n\tbeam.ParDo0(s, &nonEmptyFn{}, beam.Impulse(s), beam.SideInput{Input: col})\n\treturn col\n}\n","sourceCodeStart":176,"sourceCodeEnd":203,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/passert/passert.go#L176-L203","documentation":"passert.NonEmpty verifies at runtime (inside the pipeline, via a ParDo over an impulse with the collection as side input) that the asserted PCollection contains at least one element. The DoFn returns this error as soon as it observes that the side-input iterator yields zero elements, failing the test/pipeline. It is the Beam Go testing analog of 'expected at least one record, got none'.","triggerScenarios":"Calling passert.NonEmpty(s, col) where col resolves to an empty PCollection: the nonEmptyFn.ProcessElement side-input iterator returns false on its first call, and the DoFn returns errors.New(\"PCollection is empty, want non-empty collection\").","commonSituations":"Test pipelines whose source filter matched no records; reading from an empty test set (e.g. ptest.Create with an empty slice upstream); a transform upstream dropped all elements (buggy filtering/windowing); running against an empty file, empty table or empty Pub/Sub backlog.","solutions":["Inspect the upstream PCollection for emptiness: fix the test input (ptest.Create / datasource) so it actually produces elements.","Check whether an upstream filter, window trigger, or side-input join is unintentionally discarding all elements.","If emptiness is legitimate for the case being tested, replace passert.NonEmpty with passert.Empty or a size check via passert.Size.","Run the pipeline with logging/beam dump to confirm the number of elements reaching the assertion before changing assertion logic."],"exampleFix":"// before\npassert.NonEmpty(s, filtered) // fails when filter drops everything\n\n// after\nif expectedCount := countTestRecords(); expectedCount == 0 {\n    passert.Empty(s, filtered)\n} else {\n    passert.NonEmpty(s, filtered)\n}","handlingStrategy":"validation","validationCode":"if len(testRecords) == 0 {\n    // use passert.Empty instead of passert.NonEmpty\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Match the assertion (Empty vs NonEmpty vs Size) to the actual expected record count.","Seed test pipelines with ptest.Create and print intermediate counts when a test first fails.","Review filters/windows upstream of assertions whenever input data changes."],"tags":["apache-beam","go","testing","empty-collection"],"backgroundTag":"empty-result-set","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"}