Skip to content

Commit

Permalink
add test for limit col contribution
Browse files Browse the repository at this point in the history
  • Loading branch information
andicuko committed Dec 10, 2024
1 parent a65e777 commit 0cecba0
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/relation/rewriting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2184,11 +2184,38 @@ mod tests {
.unwrap();
relation.display_dot().unwrap();

let with_limited_d = relation.limit_col_contributions("id", 1);
with_limited_d.display_dot().unwrap();
let query = &ast::Query::from(&with_limited_d);
// Compute id contribution of the relation
let aggregates: Vec<(&str, Expr)> = vec![
("group_count", Expr::count(Expr::col("city"))),
("id", Expr::first(Expr::col("id"))),
];
let groups: Vec<Expr> = vec![Expr::col("id")];
let red: Relation = Relation::reduce()
.with_iter(aggregates)
.group_by_iter(groups)
.input(relation.clone())
.build();
let max_contr: Relation = Relation::reduce()
.with_iter(vec![(
"max_group_count",
Expr::max(Expr::col("group_count")),
)])
.input(red)
.build();

let query = &ast::Query::from(&max_contr);
let res = database.query(&query.to_string()).unwrap();
let val = value::Value::integer(1);
assert!(res[0][0] != val);

let with_limited_contr = relation.limit_col_contributions("id", 1);
with_limited_contr.display_dot().unwrap();
let query = &ast::Query::from(&with_limited_contr);

println!("\n{}", query);
_ = database.query(&query.to_string()).unwrap();

// Compute id contribution of the with_limited_d
let aggregates: Vec<(&str, Expr)> = vec![
("group_count", Expr::count(Expr::col("city"))),
("id", Expr::first(Expr::col("id"))),
Expand All @@ -2197,7 +2224,7 @@ mod tests {
let red: Relation = Relation::reduce()
.with_iter(aggregates)
.group_by_iter(groups)
.input(with_limited_d)
.input(with_limited_contr)
.build();
let max_contr: Relation = Relation::reduce()
.with_iter(vec![(
Expand Down

0 comments on commit 0cecba0

Please sign in to comment.