{"record":{"id":"1b8f41680929740c","repo":"apache/beam","slug":"passert-diff-input-pcolections-don-t-have-matching-types-v-v","errorCode":null,"errorMessage":"passert.Diff input PColections don't have matching types: %v != %v","messagePattern":"passert\\.Diff input PColections don't have matching types: (.+?) != (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/passert/passert.go","lineNumber":46,"sourceCode":"\t\"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/filter\"\n)\n\n//go:generate go install github.com/apache/beam/sdks/v2/go/cmd/starcgen\n//go:generate starcgen --package=passert --identifiers=diffFn,failFn,failIfBadEntries,failKVFn,failGBKFn,hashFn,sumFn,errFn,elmCountCombineFn,nonEmptyFn\n//go:generate go fmt\n\n// Diff splits 2 incoming PCollections into 3: left only, both, right only. Duplicates are\n// preserved, so a value may appear multiple times and in multiple collections. Coder\n// equality is used to determine equality. Should only be used for small collections,\n// because all values are held in memory at the same time.\nfunc Diff(s beam.Scope, a, b beam.PCollection) (left, both, right beam.PCollection) {\n\timp := beam.Impulse(s)\n\n\tta := beam.ValidateNonCompositeType(a)\n\ttb := beam.ValidateNonCompositeType(b)\n\n\tif !typex.IsEqual(ta, tb) {\n\t\tpanic(fmt.Sprintf(\"passert.Diff input PColections don't have matching types: %v != %v\", ta, tb))\n\t}\n\treturn beam.ParDo3(s, &diffFn{Type: beam.EncodedType{T: ta.Type()}}, imp, beam.SideInput{Input: a}, beam.SideInput{Input: b})\n}\n\n// diffFn computes the symmetrical multi-set difference of 2 collections, under\n// coder equality. The Go values returned may be any of the coder-equal ones.\ntype diffFn struct {\n\tType beam.EncodedType `json:\"type\"`\n}\n\nfunc (f *diffFn) ProcessElement(_ []byte, ls, rs func(*beam.T) bool, left, both, right func(t beam.T)) error {\n\tenc := beam.NewElementEncoder(f.Type.T)\n\tindexL, err := index(enc, ls)\n\tif err != nil {\n\t\treturn err\n\t}\n\tindexR, err := index(enc, rs)\n\tif err != nil {","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/passert/passert.go#L28-L64","documentation":"passert.Diff computes the symmetric multi-set difference of two PCollections and requires both inputs to have exactly equal Beam types. This panic fires when beam.ValidateNonCompositeType reports different types for the two inputs, since coder-equality comparison is meaningless across mismatched element types.","triggerScenarios":"Calling passert.Diff (or passert.Equals, which calls it) with two PCollections whose element types differ, e.g. comparing a PCollection<string> against PCollection<int>, or int vs int64 variants.","commonSituations":"Test pipelines where an upstream DoFn changed output type; comparing pre- and post-transform collections where one was mapped to a different type; numeric type mismatches (int vs int64) after JSON decoding.","solutions":["Ensure both PCollections have identical element types before Diff/Equals (insert a Map to convert).","Check the upstream transforms for type drift and align outputs.","Use beam.ParDo with typed output so the compiler enforces matching types."],"exampleFix":"// before\npassert.Equals(s, words, beam.Create(s, 1, 2, 3)) // words is PCollection<string>\n// after\npassert.Equals(s, words, beam.Create(s, \"a\", \"b\", \"c\"))","handlingStrategy":"validation","validationCode":"if !typex.IsEqual(beam.ValidateNonCompositeType(a), beam.ValidateNonCompositeType(b)) {\n    t.Fatalf(\"passert inputs have mismatched types\")\n}\npassert.Diff(s, a, b)","typeGuard":null,"tryCatchPattern":"func safeDiff(t *testing.T, s beam.Scope, a, b beam.PCollection) {\n    defer func() { if r := recover(); r != nil { t.Fatalf(\"passert.Diff panicked: %v\", r) } }()\n    passert.Diff(s, a, b)\n}","preventionTips":["Keep upstream transform output types aligned end-to-end","Normalize numeric types (int vs int64) before comparison","Write a helper that type-checks PCollections before assertions"],"tags":["go","beam","passert","type-mismatch","testing"],"backgroundTag":"type-mismatch","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"}