Query collaborators for artist.

This commit is contained in:
Hayden Heroux 2026-09-21 13:14:02 -04:00
parent f64e589058
commit 97ef657a50

View file

@ -40,7 +40,7 @@ fn write_parquet(lf: &LazyFrame, path: PlRefPath) -> Result<(), PolarsError> {
Ok(())
}
#[derive(Clone, ValueEnum)]
#[derive(PartialEq, Clone, ValueEnum)]
enum SourceKind {
CSV,
Parquet,
@ -48,9 +48,10 @@ enum SourceKind {
#[derive(Parser)]
struct Cli {
source: SourceKind,
from: PlRefPath,
name: String,
#[arg(value_enum, default_value = "parquet")]
source: SourceKind,
to: Option<PlRefPath>,
}
@ -62,22 +63,39 @@ fn main() -> Result<(), PolarsError> {
SourceKind::Parquet => read_parquet(args.from)?,
};
if let Some(to) = args.to {
write_parquet(&all_data, to)?;
if args.source == SourceKind::CSV {
if let Some(to) = args.to {
write_parquet(&all_data, to)?;
}
}
let writer_is_name = col("RoleType")
.eq(lit("W"))
.and(col("Name").str().contains_literal(lit(args.name)));
let is_writer = col("RoleType").eq(lit("W"));
let contains_name = col("Name").str().contains_literal(lit(args.name.clone()));
let song_titles = all_data
.filter(writer_is_name)
let artist_song_ids = all_data
.clone()
.filter(is_writer.clone().and(contains_name.clone()))
.select([col("SongID")])
.unique(None, UniqueKeepStrategy::Any)
.sort(["Title"], Default::default())
.select([col("SongID"), col("Title")])
.collect()?;
println!("{}", song_titles);
let collaborators = all_data
.filter(is_writer)
.join(
artist_song_ids.lazy(),
[col("SongID")],
[col("SongID")],
JoinArgs::new(JoinType::Inner),
)
.filter(contains_name.not())
.group_by([col("Name")])
.agg([len().alias("Count")])
.sort(
["Count"],
SortMultipleOptions::default().with_order_descending(true),
);
println!("{}", collaborators.collect()?);
Ok(())
}