{"record":{"id":"88e349c7b24b5e23","repo":"apache/beam","slug":"failed-to-map-row-t","errorCode":null,"errorMessage":"failed to map row %T","messagePattern":"failed to map row %T","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/databaseio/database.go","lineNumber":205,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tvar val beam.X\n\tfor iter(&val) {\n\t\tvar row []any\n\t\tvar data map[string]any\n\t\tif writer, ok := val.(Writer); ok {\n\t\t\tif data, err = writer.SaveData(); err == nil {\n\t\t\t\trow = make([]any, len(columns))\n\t\t\t\tfor i, column := range columns {\n\t\t\t\t\trow[i] = data[column]\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\trow, err = mapper(reflect.ValueOf(val))\n\t\t}\n\t\tif err != nil {\n\t\t\treturn errors.Wrapf(err, \"failed to map row %T\", val)\n\t\t}\n\t\tif err = writer.add(row); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif err := writer.writeBatchIfNeeded(ctx, db); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\tif err := writer.writeIfNeeded(ctx, db); err != nil {\n\t\treturn err\n\t}\n\n\tlog.Infof(ctx, \"written %v row(s) into %v\", writer.totalCount, f.Table)\n\treturn nil\n}\n","sourceCodeStart":187,"sourceCodeEnd":222,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/databaseio/database.go#L187-L222","documentation":"Raised when the per-row mapper fails to convert an element of the input PCollection into the []any row slice used for the batch INSERT. It wraps the underlying mapper error and includes the Go type of the offending value (%T). It fires for non-Writer elements whose reflection-based mapping (newWriterRowMapper) cannot produce a value for the discovered table columns.","triggerScenarios":"Emitting elements into databaseio.Write whose type does not implement the Writer interface and whose fields cannot be mapped onto the table columns (mismatched or unexported struct fields per mapFields); a SaveData() error on a Writer-implementing element; nil or unexpected element types reaching the DoFn.","commonSituations":"Struct element type whose fields don't match the table column names (renamed column, renamed field); using a non-struct custom type instead of a struct; schema drift after the table was altered; passing pointer/alias types with no matching exported fields.","solutions":["Make the element type's exported fields match the target table's column names (case-insensitive, per mapFields).","Implement the Writer interface (SaveData) on your element type to control column-to-value mapping explicitly.","Compare the discovered table columns (from the probe SELECT) with your struct fields; add/rename fields accordingly.","Read the wrapped inner error — it names the specific field or mapping failure."],"exampleFix":"// before\ntype User struct { Name string; City string } // no matching column \"city\" in table\n// after\ntype User struct { Name string; City string `beam:\"city\"` } // or align field names with table columns","handlingStrategy":"validation","validationCode":"// element type check before calling Write\nfunc checkMappableToColumns(v any, columns []string) error {\n    if _, ok := v.(databaseio.Writer); ok { return nil }\n    t := reflect.TypeOf(v)\n    if t.Kind() != reflect.Struct { return fmt.Errorf(\"element %T is not a struct or Writer\", v) }\n    fields := map[string]bool{}\n    for i := 0; i < t.NumField(); i++ { fields[strings.ToLower(t.Field(i).Name)] = true }\n    for _, c := range columns {\n        if !fields[strings.ToLower(c)] { return fmt.Errorf(\"no field maps to column %q\", c) }\n    }\n    return nil\n}","typeGuard":"func isWriter(v any) bool { _, ok := v.(databaseio.Writer); return ok }\nfunc isStructWithColumns(v any, columns []string) bool {\n    t := reflect.TypeOf(v)\n    if t.Kind() != reflect.Struct { return false }\n    for i := 0; i < t.NumField(); i++ {\n        f := strings.ToLower(t.Field(i).Name)\n        match := false\n        for _, c := range columns { if strings.ToLower(c) == f { match = true } }\n        if !match { return false }\n    }\n    return true\n}","tryCatchPattern":"if err != nil {\n    return errors.Wrapf(err, \"element of type %T could not be mapped to table columns; check field names vs table schema\", val)\n}","preventionTips":["Keep struct field names aligned with table column names (case-insensitive).","Implement the Writer/SaveData interface when you need explicit control over column mapping.","Re-validate element types after any table schema migration.","Write a unit test mapping one element through the mapper before running the full pipeline."],"tags":["reflection","type-mapping","beam-io","struct-mapping"],"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"}