Query collaborators for artist.
This commit is contained in:
parent
f64e589058
commit
97ef657a50
1 changed files with 30 additions and 12 deletions
42
src/main.rs
42
src/main.rs
|
|
@ -40,7 +40,7 @@ fn write_parquet(lf: &LazyFrame, path: PlRefPath) -> Result<(), PolarsError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, ValueEnum)]
|
#[derive(PartialEq, Clone, ValueEnum)]
|
||||||
enum SourceKind {
|
enum SourceKind {
|
||||||
CSV,
|
CSV,
|
||||||
Parquet,
|
Parquet,
|
||||||
|
|
@ -48,9 +48,10 @@ enum SourceKind {
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
source: SourceKind,
|
|
||||||
from: PlRefPath,
|
from: PlRefPath,
|
||||||
name: String,
|
name: String,
|
||||||
|
#[arg(value_enum, default_value = "parquet")]
|
||||||
|
source: SourceKind,
|
||||||
to: Option<PlRefPath>,
|
to: Option<PlRefPath>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,22 +63,39 @@ fn main() -> Result<(), PolarsError> {
|
||||||
SourceKind::Parquet => read_parquet(args.from)?,
|
SourceKind::Parquet => read_parquet(args.from)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(to) = args.to {
|
if args.source == SourceKind::CSV {
|
||||||
write_parquet(&all_data, to)?;
|
if let Some(to) = args.to {
|
||||||
|
write_parquet(&all_data, to)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let writer_is_name = col("RoleType")
|
let is_writer = col("RoleType").eq(lit("W"));
|
||||||
.eq(lit("W"))
|
let contains_name = col("Name").str().contains_literal(lit(args.name.clone()));
|
||||||
.and(col("Name").str().contains_literal(lit(args.name)));
|
|
||||||
|
|
||||||
let song_titles = all_data
|
let artist_song_ids = all_data
|
||||||
.filter(writer_is_name)
|
.clone()
|
||||||
|
.filter(is_writer.clone().and(contains_name.clone()))
|
||||||
|
.select([col("SongID")])
|
||||||
.unique(None, UniqueKeepStrategy::Any)
|
.unique(None, UniqueKeepStrategy::Any)
|
||||||
.sort(["Title"], Default::default())
|
|
||||||
.select([col("SongID"), col("Title")])
|
|
||||||
.collect()?;
|
.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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue