zhuqi-lucas commented on code in PR #27021:
URL: https://github.com/apache/datafusion/pull/27021#discussion_r4520464461
##########
datafusion/datasource-csv/src/source.rs:
##########
@@ -440,26 +774,46 @@ impl FileOpener for CsvOpener {
)
})?;
+ // A partition may start mid-file, so the header is fetched
+ // separately. Every byte-range partition of a file repeats
this
+ // small request; cache per file if that becomes costly.
+ let mapping = if match_by_header {
+ let header =
+ fetch_header(&config, store.as_ref(), &location,
file_size)
+ .await?;
+ // A partition starting within leading comment lines owns
+ // the header row, so it has to skip it.
+ if raw_start <= header.start as u64 {
Review Comment:
I think this ownership check can disagree with `AlignedBoundaryStream`'s
convention and silently drop one data row in an edge case.
For `raw_start != 0` the aligned stream fetches from `raw_start - 1` and
skips through the **first terminator**, so the partition owns the header only
when there is a terminator in `[raw_start - 1, header.start)`. When that window
contains none -- e.g. a UTF-8 BOM (no newline in its 3 bytes), or a blank line
ended by a lone `\r` while alignment scans for `\n` -- the aligned stream
starts *after* the header's own terminator, yet `raw_start <= header.start`
still holds, so `has_header = true` makes the decoder skip its first record,
which is the **first data row**.
Repro shape: file `\u{feff}a,b\n1,x\n2,y\n` (header starts at byte 3) with a
byte-range partition starting at `raw_start` 1, 2 or 3: the previous partition
owns BOM+header (and correctly skips it), while this partition skips `1,x`.
Whenever the condition matters we have `raw_start - 1 < header.start <=
prefix.len()`, so the exact test can be computed from the bytes `fetch_header`
already read: own the header iff `raw_start == 0` or `prefix[raw_start as usize
- 1..header.start]` contains the alignment terminator (e.g. have `fetch_header`
also return the aligned start, or the prefix).
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]