apache/beam · error
passert.Diff input PColections don't have matching types
Error message
passert.Diff input PColections don't have matching types: %v != %v
What it means
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.
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.
Example fix
// before passert.Equals(s, words, beam.Create(s, 1, 2, 3)) // words is PCollection<string> // after passert.Equals(s, words, beam.Create(s, "a", "b", "c"))
Defensive patterns
Strategy: validation
Validate before calling
if !typex.IsEqual(beam.ValidateNonCompositeType(a), beam.ValidateNonCompositeType(b)) {
t.Fatalf("passert inputs have mismatched types")
}
passert.Diff(s, a, b) Try / catch
func safeDiff(t *testing.T, s beam.Scope, a, b beam.PCollection) {
defer func() { if r := recover(); r != nil { t.Fatalf("passert.Diff panicked: %v", r) } }()
passert.Diff(s, a, b)
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- type must be a non-complex number
- missing entries (missing in actual, present in expected)
- observed PCollection has incompatible type
- passert.Count( ) = , want
- passert.Hash( ) = ( , ), want ( , )
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/1b8f41680929740c.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/testing/passert/passert.go:46
"github.com/apache/beam/sdks/v2/go/pkg/beam/transforms/filter"
)
//go:generate go install github.com/apache/beam/sdks/v2/go/cmd/starcgen
//go:generate starcgen --package=passert --identifiers=diffFn,failFn,failIfBadEntries,failKVFn,failGBKFn,hashFn,sumFn,errFn,elmCountCombineFn,nonEmptyFn
//go:generate go fmt
// Diff splits 2 incoming PCollections into 3: left only, both, right only. Duplicates are
// preserved, so a value may appear multiple times and in multiple collections. Coder
// equality is used to determine equality. Should only be used for small collections,
// because all values are held in memory at the same time.
func Diff(s beam.Scope, a, b beam.PCollection) (left, both, right beam.PCollection) {
imp := beam.Impulse(s)
ta := beam.ValidateNonCompositeType(a)
tb := beam.ValidateNonCompositeType(b)
if !typex.IsEqual(ta, tb) {
panic(fmt.Sprintf("passert.Diff input PColections don't have matching types: %v != %v", ta, tb))
}
return beam.ParDo3(s, &diffFn{Type: beam.EncodedType{T: ta.Type()}}, imp, beam.SideInput{Input: a}, beam.SideInput{Input: b})
}
// diffFn computes the symmetrical multi-set difference of 2 collections, under
// coder equality. The Go values returned may be any of the coder-equal ones.
type diffFn struct {
Type beam.EncodedType `json:"type"`
}
func (f *diffFn) ProcessElement(_ []byte, ls, rs func(*beam.T) bool, left, both, right func(t beam.T)) error {
enc := beam.NewElementEncoder(f.Type.T)
indexL, err := index(enc, ls)
if err != nil {
return err
}
indexR, err := index(enc, rs)
if err != nil {View on GitHub (pinned to 12126d8942)