Skip to content

Commit

Permalink
Add CSV Decoder::capacity (apache#3674)
Browse files Browse the repository at this point in the history
  • Loading branch information
tustvold committed Feb 8, 2023
1 parent b79f27b commit 73a7644
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions arrow-csv/src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,10 +438,10 @@ impl<R: BufRead> BufReader<R> {
loop {
let buf = self.reader.fill_buf()?;
let decoded = self.decoder.decode(buf)?;
if decoded == 0 {
self.reader.consume(decoded);
if decoded == 0 || self.decoder.capacity() == 0 {
break;
}
self.reader.consume(decoded);
}

self.decoder.flush()
Expand Down Expand Up @@ -574,6 +574,11 @@ impl Decoder {
self.line_number += rows.len();
Ok(Some(batch))
}

/// Returns the number of records that can be read before requiring a call to [`Self::flush`]
pub fn capacity(&self) -> usize {
self.batch_size - self.record_decoder.len()
}
}

/// Parses a slice of [`StringRecords`] into a [RecordBatch]
Expand Down

0 comments on commit 73a7644

Please sign in to comment.