Skip to content

Commit

Permalink
Merge pull request #228 from Qrlew/fix_issue_226
Browse files Browse the repository at this point in the history
Fixed DP rewriting for join of PUP and DP relations
  • Loading branch information
ngrislain authored Dec 19, 2023
2 parents 602bf61 + 1dda2dc commit be2cb94
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ 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
- DP rewriting for join of PUP and DP relations [#228](https://github.com/Qrlew/qrlew/issues/228)


## [0.6.0] - 2023-12-18
### Added
Expand Down
4 changes: 2 additions & 2 deletions src/privacy_unit_tracking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl<'a> PrivacyUnitTracking<'a> {
}
}

/// Join privacy tracking from 2 PUP relations
/// Join privacy tracking from a published and a PUP relations
pub fn join_left_published(
//TODO this need to be cleaned (really)
&self,
Expand Down Expand Up @@ -435,7 +435,7 @@ impl<'a> PrivacyUnitTracking<'a> {
PUPRelation::try_from(relation)
}

/// Join privacy tracking from 2 PUP relations
/// Join privacy tracking from a PUP and a published relations
pub fn join_right_published(
//TODO this need to be cleaned (really)
&self,
Expand Down
6 changes: 5 additions & 1 deletion src/rewriting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ mod tests {
),
("order_table", vec![("user_id", "user_table", "id")], "name"),
("user_table", vec![], "name"),
("table_1", vec![], PrivacyUnit::privacy_unit_row())
]);
let budget = Budget::new(1., 1e-3);

Expand All @@ -187,13 +188,16 @@ mod tests {
"SELECT order_id, sum(price), sum(distinct price) FROM item_table GROUP BY order_id HAVING count(*) > 2",
"SELECT order_id, sum(order_id) FROM item_table GROUP BY order_id",
"SELECT order_id As my_order, sum(price) FROM item_table GROUP BY my_order",
"SELECT order_id, MAX(order_id), sum(price) FROM item_table GROUP BY order_id"
"SELECT order_id, MAX(order_id), sum(price) FROM item_table GROUP BY order_id",
"WITH my_avg AS (SELECT AVG(price) AS avg_price, STDDEV(price) AS std_price FROM item_table WHERE price > 1.) SELECT AVG((price - avg_price) / std_price) FROM item_table CROSS JOIN my_avg WHERE std_price > 1.",
"WITH my_avg AS (SELECT MIN(price) AS min_price, MAX(price) AS max_price FROM item_table WHERE price > 1.) SELECT AVG(price - min_price) FROM item_table CROSS JOIN my_avg",
];

for q in queries {
println!("=================================\n{q}");
let query = parse(q).unwrap();
let relation = Relation::try_from(query.with(&relations)).unwrap();
relation.display_dot().unwrap();
let relation_with_private_query = relation
.rewrite_with_differential_privacy(&relations, synthetic_data.clone(), privacy_unit.clone(), budget.clone())
.unwrap();
Expand Down
8 changes: 8 additions & 0 deletions src/rewriting/rewriting_rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,10 @@ impl<'a> RewriteVisitor<'a> for Rewriter<'a> {
[Property::Published, Property::PrivacyUnitPreserving],
Property::PrivacyUnitPreserving,
Parameters::PrivacyUnit(privacy_unit),
) | (
[Property::DifferentiallyPrivate, Property::PrivacyUnitPreserving],
Property::PrivacyUnitPreserving,
Parameters::PrivacyUnit(privacy_unit),
) => {
let privacy_unit_tracking = PrivacyUnitTracking::new(
self.0,
Expand All @@ -1229,6 +1233,10 @@ impl<'a> RewriteVisitor<'a> for Rewriter<'a> {
[Property::PrivacyUnitPreserving, Property::Published],
Property::PrivacyUnitPreserving,
Parameters::PrivacyUnit(privacy_unit),
) | (
[Property::PrivacyUnitPreserving, Property::DifferentiallyPrivate],
Property::PrivacyUnitPreserving,
Parameters::PrivacyUnit(privacy_unit),
) => {
let privacy_unit_tracking = PrivacyUnitTracking::new(
self.0,
Expand Down

0 comments on commit be2cb94

Please sign in to comment.