[Feature Request]: [YAML] Support error_handling dead-letter output on ReadFromCsv and ReadFromJson
What would you like to happen?
Beam YAML supports declarative error_handling: {output: errors} dead-letter routing on MapToFields, Filter, ReadFromPubSub, ReadFromKafka, ReadFromSpanner, and WriteToBigQuery, but not on ReadFromCsv or ReadFromJson (sdks/python/apache_beam/yaml/standard_io.yaml:174-224, backed by apache_beam.io.ReadFromCsv / ReadFromJson).
In real-world file ingestion, CSV and JSONL files are the #1 place malformed rows appear (corrupt numeric cells, truncated lines, unexpected column counts, invalid UTF-8, or malformed JSON objects). Today, a single corrupt line in one shard of gs://bucket/raw/*.csv fails the entire pipeline with no way in Beam YAML to route bad records to a dead-letter sink while preserving RFC-4180 quoted multiline fields and per-shard headers.
Supporting error_handling: {output: errors} on ReadFromCsv and ReadFromJson—emitting structured error rows containing the offending raw record/line, source file path, and parse/coercion error message—would bring file sources to full parity with Beam YAML's streaming and database connectors.
Issue Priority
Priority: 2 (default / most feature requests should be filed as P2)
Issue Components
- [x] Component: Python SDK
- [ ] Component: Java SDK
- [ ] Component: Go SDK
- [ ] Component: Typescript SDK
- [ ] Component: IO connector
- [ ] Component: Beam YAML
- [ ] Component: Beam examples
- [ ] Component: Beam playground
- [ ] Component: Beam katas
- [ ] Component: Website
- [ ] Component: Infrastructure
- [ ] Component: Spark Runner
- [ ] Component: Flink Runner
- [ ] Component: Prism Runner
- [ ] Component: Hazelcast Jet Runner
- [ ] Component: Google Cloud Dataflow Runner
I'd like to work on this.
I read yaml_errors.py and how ReadFromPubSub takes error_handling in yaml_io.py. I also saw that the YAML ReadFromCsv and ReadFromJson map directly to apache_beam.io.ReadFromCsv / ReadFromJson, which parse each file chunk with pandas.
Plan:
- Add an error_handling parameter to ReadFromCsv and ReadFromJson in YAML.
- Send each bad record to the error output with the raw record, the source file path, and the error message.
- Add tests for malformed CSV rows, malformed JSON lines, and quoted multiline CSV fields.
One design question: pandas fails the whole chunk when one row is bad. Is it OK to add a record-by-record read path in yaml_io.py that runs only when error_handling is set? Or do you prefer the change inside the pandas-based reader?
.take-issue