apache/beam · critical
type must be a named type (not anonymous) for registration
Error message
type %v must be a named type (not anonymous) for registration
What it means
checkTypeRegistered panics when the struct type used for BigQuery schema inference is an anonymous type (unnamed struct literal type, e.g. from an inline struct or reflection-created type). The Beam runtime requires a stable, named type key for serialization and type registration, and runtime.TypeKey returns ok=false for anonymous types.
Solutions
- Declare a named Go type (type MyRow struct {...}) and use it as the PCollection element type.
- Replace anonymous inline structs passed to beam.Create with instances of a package-level named struct.
- If the type comes from a third-party package, wrap it in your own named struct.
Example fix
// before
bigqueryio.Write(s, proj, ds, table, beam.Create(s, struct{ N int }{1}))
// after
type MyRow struct {
N int `bigquery:"n"`
}
bigqueryio.Write(s, proj, ds, table, beam.Create(s, MyRow{N: 1})) Defensive patterns
Strategy: validation
Validate before calling
t := reflectx.SkipPtr(col.Type().Type())
if t.Name() == "" {
return fmt.Errorf("element type %v must be a named type", t)
} Type guard
func isNamedType(t reflect.Type) bool {
return t.Name() != ""
} Try / catch
defer func() {
if r := recover(); r != nil {
log.Fatalf("type registration check failed: %v", r)
}
}() Prevention
- Never use anonymous structs as PCollection element types.
- Declare row types at package level with clear names.
- Avoid reflect.StructOf for pipeline element types.
When it happens
Trigger: Using an anonymous struct in bigqueryio.Read/Write, e.g. beam.Create(s, struct{ Name string }{"x"}) or a PCollection whose element type is an unnamed struct{} literal type rather than a declared named type.
Common situations: Declaring rows inline inside beam.Create or a DoFn's emit without naming the type; generating struct types dynamically with reflect.StructOf; test code with ad-hoc anonymous structs.
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
- schema type must be struct
- type is not registered. Ensure that beam.RegisterType( ) is…
- requires either a Table or Query specified, received none
- AfterProcessingTime trigger set without a delay or…
- At least one subtrigger required for composite triggers.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/a6ac92d9d3228d53.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/io/bigqueryio/bigquery.go:238
func mustInferSchema(t reflect.Type) bigquery.Schema {
if t.Kind() != reflect.Struct {
panic(fmt.Sprintf("schema type must be struct: %v", t))
}
checkTypeRegistered(t)
schema, err := bigquery.InferSchema(reflect.Zero(t).Interface())
if err != nil {
panic(errors.Wrapf(err, "invalid schema type: %v", t))
}
return schema
}
func checkTypeRegistered(t reflect.Type) {
t = reflectx.SkipPtr(t)
key, ok := runtime.TypeKey(t)
if !ok {
panic(fmt.Sprintf("type %v must be a named type (not anonymous) for registration", t))
}
if _, registered := runtime.LookupType(key); !registered {
panic(fmt.Sprintf("type %v is not registered. Ensure that beam.RegisterType(%v) "+
"is called before beam.Init().", t, t))
}
}
func mustParseTable(table string) QualifiedTableName {
qn, err := NewQualifiedTableName(table)
if err != nil {
panic(err)
}
return qn
}
// TODO(herohde) 7/14/2017: allow WriteDispositions. The default
// is not quite what the Dataflow examples do.View on GitHub (pinned to 12126d8942)