pub trait RelationFileExt: Relation {
// Required methods
fn from_parquet<P: AsRef<Path>>(filepath: P) -> Result<Self, RelationError>
where Self: Sized;
fn from_csv<P: AsRef<Path>>(filepath: P) -> Result<Self, RelationError>
where Self: Sized;
}Expand description
Loads a Relation from a CSV or Parquet file.
Defined as an extension trait (with a blanket impl over every
Relation) so file-loading is added without bloating the core trait
or requiring each concrete data structure to reimplement it. Anything
that implements Relation automatically gains
from_csv and from_parquet.
Required Methods§
Sourcefn from_parquet<P: AsRef<Path>>(filepath: P) -> Result<Self, RelationError>where
Self: Sized,
fn from_parquet<P: AsRef<Path>>(filepath: P) -> Result<Self, RelationError>where
Self: Sized,
Creates a new relation from a Parquet file.
Column names are extracted from the Parquet schema and the relation
name is taken from the file stem. All columns must be Int64 and
every value must be non-negative so it fits in usize.
§Errors
Returns a RelationError if any of the following occur:
RelationError::Io— the file cannot be opened.RelationError::Parquet— the file is not a valid Parquet file or the reader cannot be constructed.RelationError::Arrow— a record batch fails to decode.RelationError::InvalidData— anInt64value cannot be converted tousize(e.g. it is negative).
Sourcefn from_csv<P: AsRef<Path>>(filepath: P) -> Result<Self, RelationError>where
Self: Sized,
fn from_csv<P: AsRef<Path>>(filepath: P) -> Result<Self, RelationError>where
Self: Sized,
Creates a new relation from a CSV file.
The first row is treated as a header providing attribute names; each
subsequent row is one tuple. Every field must parse as a usize. The
relation name is taken from the file stem.
§Errors
Returns a RelationError if any of the following occur:
RelationError::Io— the file cannot be opened.RelationError::Csv— the CSV reader cannot parse the header or a row (e.g. inconsistent column count).RelationError::InvalidData— a field cannot be parsed as ausize; the message identifies the offending row and column.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<R> RelationFileExt for Rwhere
R: Relation,
Blanket implementation of RelationFileExt for any type that
implements Relation.