Skip to content

Commit

Permalink
protect -> privacy
Browse files Browse the repository at this point in the history
  • Loading branch information
victoria de sainte agathe committed Dec 8, 2023
1 parent 6b6eb30 commit fa37290
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
## Added
- implemented row protection [#215](https://github.com/Qrlew/qrlew/issues/215)
- implemented row privacy [#215](https://github.com/Qrlew/qrlew/issues/215)

## [0.5.4] - 2023-12-05
- implemented `STD` and `VAR`aggregations in the dp rewritting [#205](https://github.com/Qrlew/qrlew/issues/205)
Expand Down
28 changes: 14 additions & 14 deletions src/privacy_unit_tracking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ impl Deref for PUPRelation {
}

impl Relation {
/// Add the field for the row protection
pub fn add_row_protection(self) -> Self {
/// Add the field for the row privacy
pub fn add_row_privacy(self) -> Self {
let expr = Expr::random_id((1e6 as i64) * self.size().max().unwrap());
self.identity_with_field(
PrivacyUnit::per_row_protection(),
PrivacyUnit::per_row_privacy(),
expr,
)
}
/// Add the field containing the protection unit
pub fn add_protection_unit(self, referred_field: &str) -> Self {
let relation = if referred_field == PrivacyUnit::per_row_protection() {
self.add_row_protection()
/// Add the field containing the privacy unit
pub fn add_privacy_unit(self, referred_field: &str) -> Self {
let relation = if referred_field == PrivacyUnit::per_row_privacy() {
self.add_row_privacy()
} else {
self
};
Expand All @@ -164,11 +164,11 @@ impl Relation {
.map(|f| f.name().to_string())
.filter(|name| name != &referred_field_name)
.collect();
let referred_relation = if referred_field == PrivacyUnit::per_row_protection() {
let referred_relation = if referred_field == PrivacyUnit::per_row_privacy() {
Arc::new(
referred_relation.deref()
.clone()
.add_row_protection()
.add_row_privacy()
)
} else {
referred_relation
Expand Down Expand Up @@ -214,7 +214,7 @@ impl Relation {
field_path: PrivacyUnitPath,
) -> Relation {
if field_path.path().is_empty() {
self.add_protection_unit(field_path.referred_field())
self.add_privacy_unit(field_path.referred_field())
} else {
field_path
.into_iter()
Expand All @@ -236,7 +236,7 @@ impl Relation {

impl Expr {
fn random_id(size: i64) -> Expr {
let n = namer::new_id(PrivacyUnit::per_row_protection());
let n = namer::new_id(PrivacyUnit::per_row_privacy());
Expr::cast_as_integer(
Expr::multiply(
Expr::random(n),
Expand Down Expand Up @@ -603,12 +603,12 @@ mod tests {
let relation = relation.filter_fields(|n| n != "peid");
assert!(relation.schema()[0].name() != "peid");

// with row protection
// with row privacy
// Link orders to users
let orders = relations.get(&["orders".to_string()]).unwrap().as_ref();
let relation = orders.clone().with_field_path(
&relations,
PrivacyUnitPath::from((vec![("user_id", "users", "id")], PrivacyUnit::per_row_protection())),
PrivacyUnitPath::from((vec![("user_id", "users", "id")], PrivacyUnit::per_row_privacy())),
);
relation.display_dot().unwrap();
assert!(relation.schema()[0].name() == PrivacyUnit::privacy_unit());
Expand All @@ -618,7 +618,7 @@ mod tests {
&relations,
PrivacyUnitPath::from((
vec![("order_id", "orders", "id"), ("user_id", "users", "id")],
PrivacyUnit::per_row_protection(),
PrivacyUnit::per_row_privacy(),
)),
);
relation.display_dot().unwrap();
Expand Down
8 changes: 4 additions & 4 deletions src/privacy_unit_tracking/privacy_unit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub const PRIVACY_COLUMNS: usize = 2;
pub const PRIVACY_UNIT: &str = "_PRIVACY_UNIT_";
pub const PRIVACY_UNIT_DEFAULT: &str = "_PRIVACY_UNIT_DEFAULT_";
pub const PRIVACY_UNIT_WEIGHT: &str = "_PRIVACY_UNIT_WEIGHT_";
pub const PER_ROW_PROTECTION: &str = "_RANDOM_";
pub const PER_ROW_PRIVACY: &str = "_RANDOM_";

// A few utility objects

Expand Down Expand Up @@ -270,8 +270,8 @@ impl PrivacyUnit {
PRIVACY_COLUMNS
}

pub fn per_row_protection() -> &'static str {
PER_ROW_PROTECTION
pub fn per_row_privacy() -> &'static str {
PER_ROW_PRIVACY
}

pub fn privacy_unit() -> &'static str {
Expand Down Expand Up @@ -416,7 +416,7 @@ mod tests {
),
("order_table", vec![("user_id", "user_table", "id")], "name"),
("user_table", vec![], "name"),
("product_table", vec![], PER_ROW_PROTECTION),
("product_table", vec![], PER_ROW_PRIVACY),
]);
println!("{}", privacy_unit);
}
Expand Down
16 changes: 8 additions & 8 deletions src/rewriting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ mod tests {
}

#[test]
fn test_rewrite_with_differential_privacy_with_row_protection() {
fn test_rewrite_with_differential_privacy_with_row_privacy() {
let database = postgresql::test_database();
let relations = database.relations();
let query = parse("SELECT order_id, sum(price) FROM item_table GROUP BY order_id").unwrap();
Expand All @@ -211,10 +211,10 @@ mod tests {
("order_id", "order_table", "id"),
("user_id", "user_table", "id"),
],
PrivacyUnit::per_row_protection(),
PrivacyUnit::per_row_privacy(),
),
("order_table", vec![("user_id", "user_table", "id")], PrivacyUnit::per_row_protection()),
("user_table", vec![], PrivacyUnit::per_row_protection()),
("order_table", vec![("user_id", "user_table", "id")], PrivacyUnit::per_row_privacy()),
("user_table", vec![], PrivacyUnit::per_row_privacy()),
]);
let budget = Budget::new(1., 1e-3);
let relation = Relation::try_from(query.with(&relations)).unwrap();
Expand Down Expand Up @@ -269,7 +269,7 @@ mod tests {
}

#[test]
fn test_rewrite_as_privacy_unit_preserving_with_row_protection() {
fn test_rewrite_as_privacy_unit_preserving_with_row_privacy() {
let database = postgresql::test_database();
let relations = database.relations();
let query = parse("SELECT * FROM order_table").unwrap();
Expand All @@ -285,10 +285,10 @@ mod tests {
("order_id", "order_table", "id"),
("user_id", "user_table", "id"),
],
PrivacyUnit::per_row_protection(),
PrivacyUnit::per_row_privacy(),
),
("order_table", vec![("user_id", "user_table", "id")], PrivacyUnit::per_row_protection()),
("user_table", vec![], PrivacyUnit::per_row_protection()),
("order_table", vec![("user_id", "user_table", "id")], PrivacyUnit::per_row_privacy()),
("user_table", vec![], PrivacyUnit::per_row_privacy()),
]);
let budget = Budget::new(1., 1e-3);
let relation = Relation::try_from(query.with(&relations)).unwrap();
Expand Down

0 comments on commit fa37290

Please sign in to comment.