{"record":{"id":"c1996691c36ee190","repo":"apache/beam","slug":"columns-were-empty","errorCode":null,"errorMessage":"columns were empty","messagePattern":"columns were empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/databaseio/writer.go","lineNumber":93,"sourceCode":"}\n\nfunc (w *writer) writeBatchIfNeeded(ctx context.Context, db *sql.DB) error {\n\tif w.rowCount >= w.batchSize {\n\t\treturn w.write(ctx, db)\n\t}\n\treturn nil\n}\n\nfunc (w *writer) writeIfNeeded(ctx context.Context, db *sql.DB) error {\n\tif w.rowCount >= 0 {\n\t\treturn w.write(ctx, db)\n\t}\n\treturn nil\n}\n\nfunc newWriter(driver string, batchSize int, table string, columns []string) (*writer, error) {\n\tif len(columns) == 0 {\n\t\treturn nil, errors.New(\"columns were empty\")\n\t}\n\treturn &writer{\n\t\tbatchSize:              batchSize,\n\t\tcolumnCount:            len(columns),\n\t\ttable:                  table,\n\t\tbinding:                make([]any, 0),\n\t\tsqlTemplate:            fmt.Sprintf(\"INSERT INTO %v(%v) VALUES\", table, strings.Join(columns, \",\")),\n\t\tvalueTemplateGenerator: &valueTemplateGenerator{driver},\n\t}, nil\n}\n\ntype valueTemplateGenerator struct {\n\tdriver string\n}\n\nfunc (v *valueTemplateGenerator) generate(rowCount int, columnColunt int) string {\n\tswitch v.driver {\n\tcase \"postgres\", \"pgx\":","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/databaseio/writer.go#L75-L111","documentation":"databaseio's newWriter builds SQL INSERT statements from a column list; an empty columns slice would produce malformed SQL, so it rejects the call upfront with 'columns were empty'. The writer cannot determine the table's column set without it.","triggerScenarios":"Writing to a database via databaseio.Write (which routes through ProcessElement -> newWriter) with an empty columns parameter — e.g. columns derived from a schema introspection call that returned nothing, or a config key that was missing/empty.","commonSituations":"Auto-deriving columns from an empty Avro/JSON schema file; passing a nil slice from an env/config variable that was never populated; a table-name typo causing reflection/introspection to yield no columns.","solutions":["Pass an explicit non-empty column list to databaseio.Write, e.g. []string{\"id\", \"name\"}.","If columns are generated from a schema, verify the schema file/data is loaded and parsed before constructing the write transform.","Validate len(columns) > 0 in your pipeline-construction code and fail with a descriptive message."],"exampleFix":"// before\ndatabaseio.Write(scope, db, \"mytable\", nil, reflect.TypeOf(row)) // columns empty\n\n// after\ncols := []string{\"id\", \"name\", \"created_at\"}\ndatabaseio.Write(scope, db, \"mytable\", cols, reflect.TypeOf(row))","handlingStrategy":"validation","validationCode":"if len(columns) == 0 {\n\treturn fmt.Errorf(\"databaseio.Write requires a non-empty column list\")\n}\n// proceed with databaseio.Write(..., columns, ...)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Explicitly list table columns rather than deriving them from possibly-empty sources.","Validate schema/config files load and contain column definitions before pipeline construction.","Fail fast at startup when the column list is empty."],"tags":["go","apache-beam","databaseio","empty-columns","sql"],"backgroundTag":"empty-required-field","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}