Skip to main content

Reader

Struct Reader 

Source
pub struct Reader { /* private fields */ }
Expand description

A CSV file, positioned at a record boundary.

Implementations§

Source§

impl Reader

Source

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.

Source

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.

Source

pub fn fields(&self) -> Vec<Field>

The columns this reader will produce, in order.

Source

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.

Source

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.

Source

pub const fn dialect(&self) -> Dialect

How this file is punctuated, which is what the sniffer decided.

Source

pub fn next_chunk(&mut self) -> Result<Option<Chunk>>

The next chunk, or None at the end of the file.

§Errors

A read error, a malformed record, or a value that does not fit the type the sample chose for its column.

Trait Implementations§

Source§

impl Debug for Reader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.