Skip to content

Commit

Permalink
Merge pull request #133 from Qrlew/issue_128
Browse files Browse the repository at this point in the history
Fixed the order of relations in the Dot representation of `Relation::…
  • Loading branch information
ngrislain authored Sep 28, 2023
2 parents bb45678 + 0d7825e commit e9f2d47
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Order of relations in the Dot representation of `Relation::Join`[MR131](https://github.com/Qrlew/qrlew/pull/131)

## [0.3.4] - 2023-09-25
- Fixed examples
Expand Down
18 changes: 12 additions & 6 deletions src/differential_privacy/protect_grouping_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ mod tests {
vec![],
Rc::new(table.clone()),
));
let pep_rel = relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
let pep_rel =
relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
let protected_pep_rel = pep_rel.clone().protect_grouping_keys(1., 0.003).unwrap();
assert_eq!(Relation::from(pep_rel), Relation::from(protected_pep_rel));

Expand All @@ -475,7 +476,8 @@ mod tests {
vec![Expr::col("b")],
Rc::new(table.clone()),
));
let pep_rel = relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
let pep_rel =
relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
//pep_rel.display_dot();
let protected_pep_rel = pep_rel.clone().protect_grouping_keys(1., 0.003).unwrap();
//protected_pep_rel.display_dot();
Expand All @@ -498,7 +500,8 @@ mod tests {
vec![Expr::col("b")],
Rc::new(table.clone()),
));
let pep_rel = relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
let pep_rel =
relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
//pep_rel.display_dot();
let protected_pep_rel = pep_rel.clone().protect_grouping_keys(1., 0.003).unwrap();
//protected_pep_rel.display_dot();
Expand All @@ -522,7 +525,8 @@ mod tests {
vec![Expr::col("c")],
Rc::new(table.clone()),
));
let pep_rel = relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
let pep_rel =
relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
//pep_rel.display_dot();
let protected_pep_rel = pep_rel.clone().protect_grouping_keys(1., 0.003).unwrap();
//protected_pep_rel.display_dot();
Expand All @@ -547,7 +551,8 @@ mod tests {
vec![Expr::col("b"), Expr::col("c")],
Rc::new(table.clone()),
));
let pep_rel = relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
let pep_rel =
relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
//pep_rel.display_dot();
let protected_pep_rel = pep_rel.clone().protect_grouping_keys(1., 0.003).unwrap();
protected_pep_rel.display_dot();
Expand Down Expand Up @@ -599,7 +604,8 @@ mod tests {
.name("my_map")
.build();
relation.display_dot();
let pep_rel = relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
let pep_rel =
relation.force_protect_from_field_paths(&relations, vec![("table", vec![], "id")]);
//pep_rel.display_dot();
namer::reset();
let protected_pep_rel = pep_rel.clone().protect_grouping_keys(1., 0.003).unwrap();
Expand Down
6 changes: 5 additions & 1 deletion src/protection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,11 @@ mod tests {
let table = table
.protect_from_field_paths(
&relations,
vec![("item_table", vec![("order_id", "order_table", "id")], "date")],
vec![(
"item_table",
vec![("order_id", "order_table", "id")],
"date",
)],
)
.unwrap();
table.display_dot().unwrap();
Expand Down
11 changes: 7 additions & 4 deletions src/relation/dot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,13 @@ impl<'a, T: Clone + fmt::Display, V: Visitor<'a, T> + Clone>
dot::GraphWalk<'a, Node<'a, T>, Edge<'a, T>> for VisitedRelation<'a, V>
{
fn nodes(&'a self) -> dot::Nodes<'a, Node<'a, T>> {
self.0
let mut nodes = self
.0
.iter_with(self.1.clone())
.map(|(relation, t)| Node(relation, t))
.collect()
.collect::<Vec<_>>();
nodes.reverse();
nodes.into()
}

fn edges(&'a self) -> dot::Edges<'a, Edge<'a, T>> {
Expand Down Expand Up @@ -370,8 +373,8 @@ mod tests {
let join: Relation = Relation::join()
.name("join")
.cross()
.left(table.clone())
.right(map.clone())
.left(table.clone().with_name("left_relation".to_string()))
.right(map.clone().with_name("right_relation".to_string()))
.build();
println!("join = {}", join);
let map_2: Relation = Relation::map()
Expand Down
14 changes: 12 additions & 2 deletions src/relation/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,9 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor {
.collect(),
table_with_joins(reduce.input.as_ref().into(), vec![]),
None,
ast::GroupByExpr::Expressions(reduce.group_by.iter().map(ast::Expr::from).collect()),
ast::GroupByExpr::Expressions(
reduce.group_by.iter().map(ast::Expr::from).collect(),
),
vec![],
None,
),
Expand Down Expand Up @@ -451,7 +453,15 @@ impl<'a> Visitor<'a, ast::Query> for FromRelationVisitor {
},
joins: vec![],
};
query(vec![], all(), from, None, ast::GroupByExpr::Expressions(vec![]), vec![], None)
query(
vec![],
all(),
from,
None,
ast::GroupByExpr::Expressions(vec![]),
vec![],
None,
)
}
}

Expand Down
32 changes: 22 additions & 10 deletions src/sql/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,16 @@ impl<'a> Acceptor<'a> for ast::Expr {
pattern,
escape_char: _,
} => Dependencies::from([expr.as_ref(), pattern.as_ref()]),
ast::Expr::AnyOp {left, compare_op: _, right} => {
Dependencies::from([left.as_ref(), right.as_ref()])
},
ast::Expr::AllOp {left, compare_op: _, right} => {
Dependencies::from([left.as_ref(), right.as_ref()])
},
ast::Expr::AnyOp {
left,
compare_op: _,
right,
} => Dependencies::from([left.as_ref(), right.as_ref()]),
ast::Expr::AllOp {
left,
compare_op: _,
right,
} => Dependencies::from([left.as_ref(), right.as_ref()]),
ast::Expr::UnaryOp { op: _, expr } => Dependencies::from([expr.as_ref()]),
ast::Expr::Cast { expr, data_type: _ } => Dependencies::from([expr.as_ref()]),
ast::Expr::TryCast { expr, data_type: _ } => Dependencies::from([expr.as_ref()]),
Expand Down Expand Up @@ -327,12 +331,20 @@ impl<'a, T: Clone, V: Visitor<'a, T>> visitor::Visitor<'a, ast::Expr, T> for V {
pattern,
escape_char,
} => todo!(),
ast::Expr::AnyOp {left, compare_op: _, right} => {
ast::Expr::AnyOp {
left,
compare_op: _,
right,
} => {
todo!()
},
ast::Expr::AllOp {left, compare_op: _, right} => {
}
ast::Expr::AllOp {
left,
compare_op: _,
right,
} => {
todo!()
},
}
ast::Expr::UnaryOp { op, expr } => self.unary_op(op, dependencies.get(expr).clone()),
ast::Expr::Cast { expr, data_type } => todo!(),
ast::Expr::TryCast { expr, data_type } => todo!(),
Expand Down
3 changes: 2 additions & 1 deletion src/sql/relation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ impl<'a> VisitedQueryRelations<'a> {
// Prepare the GROUP BY
let group_by: Result<Vec<Expr>> = match group_by {
ast::GroupByExpr::All => todo!(),
ast::GroupByExpr::Expressions(group_by_exprs) => group_by_exprs.iter()
ast::GroupByExpr::Expressions(group_by_exprs) => group_by_exprs
.iter()
.map(|e| e.with(columns).try_into())
.collect(),
};
Expand Down

0 comments on commit e9f2d47

Please sign in to comment.