pub struct Reader { /* private fields */ }Expand description
A CSV file, positioned at a record boundary.
Implementations§
Source§impl Reader
impl Reader
Sourcepub fn open(file: Box<dyn File>, path: &str) -> Result<Self>
pub fn open(file: Box<dyn File>, path: &str) -> Result<Self>
Opens a file, works out how it is written, and positions it at the first row.
The path is kept because the error a bad value produces names it, the way DuckDB’s does.
§Errors
When the file cannot be read, and when the first block of it does not hold one whole record, which is a single line longer than a megabyte and is not a CSV file anybody meant to write.
Sourcepub fn open_with(file: Box<dyn File>, path: &str, given: Given) -> Result<Self>
pub fn open_with(file: Box<dyn File>, path: &str, given: Given) -> Result<Self>
The same, with whatever the caller already knows about how the file is written.
This is where read_csv('f.csv', delim=';', header=true) arrives. A given value replaces the
sniffer’s answer rather than seeding it, and it replaces it before the sample is split, so the
types and the column names come out of the file read the way the caller said it is written.
§Errors
Everything Reader::open reports.
Sourcepub fn project(&mut self, columns: &[usize]) -> Result<()>
pub fn project(&mut self, columns: &[usize]) -> Result<()>
Reads only these columns, by position in the file, in this order.
§Errors
When a position is past the end of the file’s columns.
Sourcepub fn retype(&mut self, types: &[LogicalType]) -> Result<()>
pub fn retype(&mut self, types: &[LogicalType]) -> Result<()>
Reads the projected columns as these types rather than as the ones the sample chose.
A read that covers several files produces one stream and a stream has one schema, and no
single file’s sample is that schema. Every file is sniffed on its own and the answers are
combined by crate::across, so each file is then told what the whole read settled on,
including the first one. Without it a file whose column happens to hold nothing but whole
numbers hands up a BIGINT column into a stream that is DOUBLE because some other file in the
set held a decimal.
This is not a cast of what was read. The type is what the text is converted with, so saying it before any row is read converts once rather than converting to the wrong type and again to the right one. A value that then does not fit is the conversion error, named and lined the way any other one is.
§Errors
When the list is not as long as the projection.