35 lines
1.2 KiB
Rust
35 lines
1.2 KiB
Rust
use polars::prelude::*;
|
|
use polars_lazy::frame::LazyCsvReader;
|
|
|
|
fn read_csv(path: PlRefPath) -> Result<LazyFrame, PolarsError> {
|
|
let schema = Schema::from_iter(vec![
|
|
Field::new("Title".into(), DataType::String),
|
|
Field::new("RoleType".into(), DataType::String),
|
|
Field::new("Name".into(), DataType::String),
|
|
Field::new("Shares".into(), DataType::String),
|
|
Field::new("Note".into(), DataType::String),
|
|
]);
|
|
|
|
let lf = LazyCsvReader::new(path).with_has_header(true).with_schema(Some(Arc::new(schema))).finish()?;
|
|
let with_song_id = lf.with_columns([col("RoleType").eq(lit("ASCAP")).cast(DataType::Int64).cum_sum(false).alias("SongID")]);
|
|
Ok(with_song_id)
|
|
}
|
|
|
|
fn main() -> Result<(), PolarsError> {
|
|
let path: PlRefPath = PlRefPath::new("ASCAP_CATALOG.csv");
|
|
let name: &str = "REBERGEN WILLEM";
|
|
|
|
let lf = read_csv(path)?;
|
|
|
|
let writer_is_name = col("RoleType").eq(lit("W")).and(col("Name").str().contains_literal(lit(name)));
|
|
|
|
let song_titles = lf.filter(writer_is_name)
|
|
.unique(None, UniqueKeepStrategy::Any)
|
|
.sort(["Title"], Default::default())
|
|
.select([col("SongID"), col("Title")])
|
|
.collect()?;
|
|
|
|
println!("{}", song_titles);
|
|
|
|
Ok(())
|
|
}
|