Ivan-gfan opened a new pull request, #13424:
URL: https://github.com/apache/seatunnel/pull/13424
### Purpose of this pull request
Fixes #13423.
With `csv_use_header_line = true` and `enable_file_split = true`, the split
strategy skips the header line (`skipHeaderRowNumber = 1`), so no split starts
at offset 0. `CsvReadStrategy` only parses the header for a split starting at
0, and otherwise uses the schema column names in schema order as the header.
Every split was therefore read by position, and a file whose column order
differs from the `schema` was read into the wrong columns, or failed on a type
conversion.
For a byte-range split that does not start at the header, `CsvReadStrategy`
now reads the header from the head of the file and matches it against the
schema, the same as an unsplit read. The header is kept for the following
splits of the same file, so consecutive splits of one file open it for the
header once.
### Does this PR introduce _any_ user-facing change?
Yes. With `csv_use_header_line = true` and `enable_file_split = true`,
columns are mapped by the header names, as they already are without
`enable_file_split`. Before, they were mapped by position in schema order.
Jobs without `csv_use_header_line`, or without `enable_file_split`, are not
affected.
### How was this patch tested?
- `CsvReadStrategyTest#testHeaderMapsColumnsByNameWhenFileIsSplit`: a file
with header `name,id,age` and schema `id,name,age` is split by
`FileSplitStrategyFactory` (`file_split_size = 48`, several splits) and each
split is read by `CsvReadStrategy`. All 20 rows must have their values in the
right columns.
- `LocalFileIT#testLocalFileCsvWithHeaderAndFileSplit`
(`csv_with_header_enable_split_to_assert.conf`): reads the two existing header
test files (`name,id,is_female` and `name,is_female,id`) with
`enable_file_split = true` and asserts the row count and the value ranges of
each column.
- Without the change in `CsvReadStrategy`, the unit test fails with
`NumberFormatException: For input string: "user1"`, and the E2E job fails with
`NumberFormatException: For input string: "tom"`.
- With the change, `LocalFileIT#testLocalFileCsv`,
`#testLocalFileCsvWithPreamble` and `#testLocalFileCsvWithHeaderAndFileSplit`
pass locally on Zeta, and so does `CsvReadStrategyTest`, except
`testReadComplexCsv` and `testSpecialQuoteCharForCsvRead`, which fail on
Windows on line endings with or without this change.
### Check list
* [x] If any new Jar binary package adding in your PR, please add License
Notice according
[New License
Guide](https://github.com/apache/seatunnel/blob/dev/docs/en/developer/new-license.md)
(no new dependency)
* [x] If necessary, please update the documentation to describe the new
feature. https://github.com/apache/seatunnel/tree/dev/docs (not needed: the
documented behavior of `csv_use_header_line` now also holds with
`enable_file_split`)
* [x] If necessary, please update `incompatible-changes.md` to describe the
incompatibility caused by this PR. (not needed)
* [ ] If you are contributing the connector code, please check that the
following files are updated: (not a new connector)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]