{"record":{"id":"c9f862bc1645b7e6","repo":"apache/beam","slug":"expected-v-row-values-but-had-v","errorCode":null,"errorMessage":"expected %v row values, but had: %v","messagePattern":"expected (.+?) row values, but had: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/databaseio/writer.go","lineNumber":51,"sourceCode":"\tSaveData() (map[string]any, error)\n}\n\ntype writer struct {\n\tbatchSize              int\n\ttable                  string\n\tsqlTemplate            string\n\tvalueTemplateGenerator *valueTemplateGenerator\n\tbinding                []any\n\tcolumnCount            int\n\trowCount               int\n\ttotalCount             int\n}\n\nfunc (w *writer) add(row []any) error {\n\tw.rowCount++\n\tw.totalCount++\n\tif len(row) != w.columnCount {\n\t\treturn errors.Errorf(\"expected %v row values, but had: %v\", w.columnCount, len(row))\n\t}\n\tw.binding = append(w.binding, row...)\n\treturn nil\n}\n\nfunc (w *writer) write(ctx context.Context, db *sql.DB) error {\n\tvalues := w.valueTemplateGenerator.generate(w.rowCount, w.columnCount)\n\tif len(values) == 0 {\n\t\tlog.Info(ctx, \"No value(s) to be written....\")\n\t\treturn nil\n\t}\n\tSQL := w.sqlTemplate + values\n\tresultSet, err := db.ExecContext(ctx, SQL, w.binding...)\n\tif err != nil {\n\t\treturn err\n\t}\n\taffected, _ := resultSet.RowsAffected()\n\tif int(affected) != w.rowCount {","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/databaseio/writer.go#L33-L69","documentation":"The databaseio writer batches row values into a single multi-row INSERT statement; every row must supply exactly one value per column of the target table (w.columnCount, derived from the table metadata). writer.add validates this before appending to the binding slice, because a short or long row would misalign every placeholder in the generated SQL. This error means the row slice handed to the writer has the wrong arity.","triggerScenarios":"A DoFn (ProcessElement) producing rows for databaseio.Write emits a []any whose length differs from the number of columns in the target table — typically when SaveData or the row-construction code doesn't return one value per column, or the table schema was altered after the pipeline was written.","commonSituations":"Adding/dropping a table column without updating the writer DoFn; building the row conditionally so some elements are omitted; using SaveData to serialize a struct where an embedded/optional field is skipped; copying an example writer for a different table shape.","solutions":["Update the row-producing code to emit exactly one value per table column, in the column order the sink was configured with","Re-check the target table schema (column count) and reconcile it with the writer","If using the Writer interface's SaveData, ensure the returned map contains an entry for every column","Add a unit test asserting len(row) == expected column count before write"],"exampleFix":"// before\nrow := []any{u.ID, u.Name} // table has 3 columns\n// after\nrow := []any{u.ID, u.Name, u.Email}","handlingStrategy":"validation","validationCode":"func validateRowLength(row []any, columnCount int) error {\n    if len(row) != columnCount {\n        return fmt.Errorf(\"row has %d values, table has %d columns\", len(row), columnCount)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := w.add(row); err != nil {\n    return fmt.Errorf(\"databaseio add failed for row %d: %w\", i, err)\n}","preventionTips":["Keep the row construction in one function tied to the table schema definition","Write a unit test asserting row arity equals the table's column count","When using SaveData, verify every column key is present in the returned map","Update writers whenever the table schema migration adds/removes columns"],"tags":["go","sql","insert","arity-mismatch"],"backgroundTag":"invalid-argument-value","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"}