Get titles by artist name.

This commit is contained in:
Hayden Heroux 2026-09-21 10:37:37 -04:00
parent be179e908d
commit db03e51cfe
4 changed files with 3581 additions and 2 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
ASCAP_CATALOG.csv
/target /target

3544
Cargo.lock generated Normal file

File diff suppressed because it is too large Load diff

View file

@ -4,3 +4,5 @@ version = "0.1.0"
edition = "2024" edition = "2024"
[dependencies] [dependencies]
polars = { version = "0.55.2", features = ["lazy", "strings", "regex"] }
polars-lazy = { version = "0.55.2", features = ["csv", "cum_agg"] }

View file

@ -1,3 +1,35 @@
fn main() { use polars::prelude::*;
println!("Hello, world!"); 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(())
} }