apache / apache/beam

TextIO should support reading header lines

Open
#18,460 0 comments 0 reactions 0 assignees View on GitHub
bug core java P3 python
Dominant language
Java
Stars
8.7k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
205

Description

Users frequently request the ability to skip some header rows when reading text files.

https://stackoverflow.com/questions/28450554/skipping-header-rows-is-it-possible-with-cloud-dataflow
https://stackoverflow.com/questions/43551876/how-do-i-read-and-transform-csv-headers-before-bigqueryio-write
https://stackoverflow.com/questions/41297704/reading-csv-header-with-dataflow
https://stackoverflow.com/questions/45554466/google-cloud-dataflow-apache-beam-how-to-process-gzipped-csv-files-with-a-he
https://stackoverflow.com/questions/44045744/how-do-i-skip-header-files-when-reading-from-google-cloud-storage-in-a-dataflow

This is also relevant for reading file formats such as VCF, see thread https://lists.apache.org/thread.html/dc7e5c3ff20d9270f06c1a298ad949da018a83f900b22d58f6b4c468@%3Cdev.beam.apache.org%3E

Python supports this partially https://github.com/apache/beam/pull/1771/files via skip_header_lines, but the header lines can have useful content, and the number of header lines is not fixed (in VCF).

We should figure out a good API for this and support this natively in TextIO. The API decisions would be:

- How do we specify how much of the beginning of each file is the header: options could be e.g. a certain number of lines; or lines that start with a certain character; or a custom predicate.
- How do we make the header contents accessible to a user of TextIO. Since the header can be different in each file, we can't return it as a PCollectionView\>. Instead I suppose, when you use a header, you'd need to specify a SerializableFunction, String\>, T\> or something like that for parsing (header, line) -\> user type. Note that currently TextIO.Read does not support returning a user type anyway, so that'd need to be done too.

Imported from Jira [BEAM-2776](https://issues.apache.org/jira/browse/BEAM-2776). Original Jira may contain additional context.
Reported by: jkff.

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing TextIO.Read API and the Python skip_header_lines implementation linked in the issue. Define how header boundaries and per-file header access should work, then verify that TextIO can return the requested user type while preserving header contents for formats such as VCF.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
data-engineering
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.