pub enum Relation {
Table(Table),
Map(Map),
Reduce(Reduce),
Join(Join),
Set(Set),
Values(Values),
}
Expand description
A Relation enum Inspired by: https://calcite.apache.org/ similar to: https://docs.rs/sqlparser/latest/sqlparser/ast/enum.TableFactor.html
Variants§
Implementations§
source§impl Relation
impl Relation
sourcepub fn join_with_grouping_values(
self,
grouping_values: Relation
) -> Result<Relation>
pub fn join_with_grouping_values( self, grouping_values: Relation ) -> Result<Relation>
We join the self
Relation
with the grouping_values Relation
;
We use a LEFT OUTER
join for guaranteeing that all the possible grouping keys are released
source§impl Relation
impl Relation
sourcepub fn privacy_unit_row(self) -> Self
pub fn privacy_unit_row(self) -> Self
Add the field for the row privacy
sourcepub fn privacy_unit(self, referred_field: &str) -> Self
pub fn privacy_unit(self, referred_field: &str) -> Self
Add the field containing the privacy unit
sourcepub fn with_referred_field(
self,
referring_id: String,
referred_relation: Arc<Relation>,
referred_id: String,
referred_field: String,
referred_field_name: String
) -> Relation
pub fn with_referred_field( self, referring_id: String, referred_relation: Arc<Relation>, referred_id: String, referred_field: String, referred_field_name: String ) -> Relation
Add a field designated with a foreign relation and a field
sourcepub fn with_field_path(
self,
relations: &Hierarchy<Arc<Relation>>,
field_path: PrivacyUnitPath
) -> Relation
pub fn with_field_path( self, relations: &Hierarchy<Arc<Relation>>, field_path: PrivacyUnitPath ) -> Relation
Add a field designated with a “field path”
source§impl Relation
impl Relation
sourcepub fn identity_with_field(self, name: &str, expr: Expr) -> Relation
pub fn identity_with_field(self, name: &str, expr: Expr) -> Relation
Add a field that derives from existing fields
sourcepub fn identity_insert_field(
self,
index: usize,
inserted_name: &str,
inserted_expr: Expr
) -> Relation
pub fn identity_insert_field( self, index: usize, inserted_name: &str, inserted_expr: Expr ) -> Relation
Insert a field that derives from existing fields
sourcepub fn with_field(self, name: &str, expr: Expr) -> Relation
pub fn with_field(self, name: &str, expr: Expr) -> Relation
Add a field that derives from input fields
sourcepub fn insert_field(
self,
index: usize,
inserted_name: &str,
inserted_expr: Expr
) -> Relation
pub fn insert_field( self, index: usize, inserted_name: &str, inserted_expr: Expr ) -> Relation
Insert a field that derives from input fields
sourcepub fn sums_by_group(self, groups: &[&str], values: &[(&str, &str)]) -> Self
pub fn sums_by_group(self, groups: &[&str], values: &[(&str, &str)]) -> Self
Returns a Relation::Reduce
built from the current Relation
.
- The group by columns are specified in the
groups
parameter. - The aggregates are the sum of the columns, where each column is identified by the second element of the corresponding tuple in the
values
parameter.
Field names of the output Relation
:
- If the aggregation is
First
, the field name is the name of the column. - If the aggregation is
Sum
, the field name is the first element of the corresponding tuple in thevalues
parameter.
sourcepub fn l1_norms(self, entities: &str, groups: &[&str], values: &[&str]) -> Self
pub fn l1_norms(self, entities: &str, groups: &[&str], values: &[&str]) -> Self
Compute L1 norms of the vectors formed by the group values for each entities
sourcepub fn l2_norms(self, entities: &str, groups: &[&str], values: &[&str]) -> Self
pub fn l2_norms(self, entities: &str, groups: &[&str], values: &[&str]) -> Self
Compute L2 norms of the vectors formed by the group values for each entities
sourcepub fn scale(
self,
entities: &str,
named_values: &[(&str, &str)],
scale_factors: Relation
) -> Self
pub fn scale( self, entities: &str, named_values: &[(&str, &str)], scale_factors: Relation ) -> Self
Returns a Relation with rescaled columns specified in values
.
The resulting relation consists of:
- The original fields from the current relation.
- Rescaled columns, where each rescaled column is a product of the original column (specified by the second element of the corresponding tuple in
values
) and its scaling factor output byscale_factors
Relation
sourcepub fn l2_clipped_sums(
self,
entities: &str,
groups: &[&str],
named_value_clippings: &[(&str, &str, f64)]
) -> Self
pub fn l2_clipped_sums( self, entities: &str, groups: &[&str], named_value_clippings: &[(&str, &str, f64)] ) -> Self
For each coordinate, rescale the columns by 1 / greatest(1, norm_l2/C)
where the l2 norm is computed for each elecment of vectors
The self
relation must contain the vectors, base and coordinates columns
For the grouping columns, the name of the output fields is the name of the column
For the clipping values, it is given by the first item of each tuple in value_clippings
sourcepub fn add_gaussian_noise(self, name_sigmas: &[(&str, f64)]) -> Relation
pub fn add_gaussian_noise(self, name_sigmas: &[(&str, f64)]) -> Relation
Add gaussian noise of a given standard deviation to the given columns
sourcepub fn add_clipped_gaussian_noise(self, name_sigmas: &[(&str, f64)]) -> Relation
pub fn add_clipped_gaussian_noise(self, name_sigmas: &[(&str, f64)]) -> Relation
Add gaussian noise of a given standard deviation to the given columns, while keeping the column min and max
sourcepub fn filter(self, predicate: Expr) -> Relation
pub fn filter(self, predicate: Expr) -> Relation
Returns a Relation::Map
that inputs self
and filter by predicate
sourcepub fn filter_columns(
self,
columns: BTreeMap<&str, (Option<Value>, Option<Value>, Vec<Value>)>
) -> Relation
pub fn filter_columns( self, columns: BTreeMap<&str, (Option<Value>, Option<Value>, Vec<Value>)> ) -> Relation
Returns a filtered Relation
§Arguments
columns
:Vec<(column_name, minimal_value, maximal_value, possible_values)>
For example,
filter_columns(vec![("my_col", Value::float(2.), Value::float(10.), vec![Value::integer(4), Value::integer(9)])])
returns a filtered Relation
whose filter
is equivalent to (my_col > 2.) and (my_col < 10) and (my_col in (4, 9)
sourcepub fn poisson_sampling(self, proba: f64) -> Relation
pub fn poisson_sampling(self, proba: f64) -> Relation
Poisson sampling of a relation. It samples each line with probability 0 <= proba <= 1
sourcepub fn sampling_without_replacements(
self,
rate: f64,
rate_multiplier: f64
) -> Relation
pub fn sampling_without_replacements( self, rate: f64, rate_multiplier: f64 ) -> Relation
sampling without replacemnts. It creates a Map using self as an imput which applies WHERE RANDOM() < rate_multiplier * rate ORDER BY RANDOM() LIMIT rate*size and preserves the input schema fields. WHERE RANDOM() < rate_multiplier * rate is for optimization purposes
sourcepub fn distinct(self) -> Relation
pub fn distinct(self) -> Relation
GROUP BY all the fields. This mimicks the sql DISTINCT
in the
SELECT
clause.
sourcepub fn distinct_aggregates(
self,
column: &str,
group_by: Vec<&str>,
aggregates: Vec<(&str, Aggregate)>
) -> Relation
pub fn distinct_aggregates( self, column: &str, group_by: Vec<&str>, aggregates: Vec<(&str, Aggregate)> ) -> Relation
Build a relation whose output fields are to the aggregations in aggregates
applied on the UNIQUE values of the column column
and grouped by the columns in group_by
.
If grouping_by
is not empty, we order by the grouping expressions.
pub fn public_values_column(&self, col_name: &str) -> Result<Relation>
pub fn public_values(&self) -> Result<Relation>
sourcepub fn cross_join(self, right: Self) -> Result<Relation>
pub fn cross_join(self, right: Self) -> Result<Relation>
Returns the cross join between self
and right
where
the output names of the fields are conserved.
This fails if one column name is contained in both relations
sourcepub fn natural_inner_join(self, right: Self) -> Relation
pub fn natural_inner_join(self, right: Self) -> Relation
Returns the outer join between self
and right
where
the output names of the fields are conserved.
The joining criteria is the equality of columns with the same name
source§impl Relation
impl Relation
pub fn inputs(&self) -> Vec<&Relation>
pub fn input_schemas(&self) -> Vec<&Schema>
pub fn input_fields(&self) -> Vec<&Field>
sourcepub fn table() -> TableBuilder<WithoutSchema>
pub fn table() -> TableBuilder<WithoutSchema>
Build a table
sourcepub fn map() -> MapBuilder<WithoutInput>
pub fn map() -> MapBuilder<WithoutInput>
Build a map
sourcepub fn reduce() -> ReduceBuilder<WithoutInput>
pub fn reduce() -> ReduceBuilder<WithoutInput>
Build a reduce
sourcepub fn join() -> JoinBuilder<WithoutInput, WithoutInput>
pub fn join() -> JoinBuilder<WithoutInput, WithoutInput>
Build a reduce
sourcepub fn set() -> SetBuilder<WithoutInput, WithoutInput>
pub fn set() -> SetBuilder<WithoutInput, WithoutInput>
Build a reduce
sourcepub fn values() -> ValuesBuilder
pub fn values() -> ValuesBuilder
Build a values
source§impl Relation
impl Relation
sourcepub fn with_attributes<'a, Attributes: Clone>(
&'a self,
attributes: Attributes
) -> RelationWithAttributes<'a, Attributes>
pub fn with_attributes<'a, Attributes: Clone>( &'a self, attributes: Attributes ) -> RelationWithAttributes<'a, Attributes>
Add attributes to Relation
sourcepub fn with_default_attributes<'a, Attributes: Clone + Default>(
&'a self
) -> RelationWithAttributes<'a, Attributes>
pub fn with_default_attributes<'a, Attributes: Clone + Default>( &'a self ) -> RelationWithAttributes<'a, Attributes>
Add attributes to Relation
source§impl Relation
impl Relation
sourcepub fn set_attributes<'a, Attributes: 'a + Clone + Debug + Hash + Eq, S: 'a + SetAttributesVisitor<'a, Attributes>>(
&'a self,
set_attributes_visitor: S
) -> RelationWithAttributes<'a, Attributes>
pub fn set_attributes<'a, Attributes: 'a + Clone + Debug + Hash + Eq, S: 'a + SetAttributesVisitor<'a, Attributes>>( &'a self, set_attributes_visitor: S ) -> RelationWithAttributes<'a, Attributes>
Take a relation and set rewriting rules
source§impl Relation
impl Relation
sourcepub fn set_rewriting_rules<'a, S: 'a + SetRewritingRulesVisitor<'a>>(
&'a self,
set_rewriting_rules_visitor: S
) -> RelationWithRewritingRules<'a>
pub fn set_rewriting_rules<'a, S: 'a + SetRewritingRulesVisitor<'a>>( &'a self, set_rewriting_rules_visitor: S ) -> RelationWithRewritingRules<'a>
Take a relation and set rewriting rules
source§impl Relation
impl Relation
sourcepub fn rewrite_as_privacy_unit_preserving<'a>(
&'a self,
relations: &'a Hierarchy<Arc<Relation>>,
synthetic_data: Option<SyntheticData>,
privacy_unit: PrivacyUnit,
dp_parameters: DpParameters
) -> Result<RelationWithDpEvent>
pub fn rewrite_as_privacy_unit_preserving<'a>( &'a self, relations: &'a Hierarchy<Arc<Relation>>, synthetic_data: Option<SyntheticData>, privacy_unit: PrivacyUnit, dp_parameters: DpParameters ) -> Result<RelationWithDpEvent>
Rewrite the query so that the privacy unit is tracked through the query.
sourcepub fn rewrite_with_differential_privacy<'a>(
&'a self,
relations: &'a Hierarchy<Arc<Relation>>,
synthetic_data: Option<SyntheticData>,
privacy_unit: PrivacyUnit,
dp_parameters: DpParameters
) -> Result<RelationWithDpEvent>
pub fn rewrite_with_differential_privacy<'a>( &'a self, relations: &'a Hierarchy<Arc<Relation>>, synthetic_data: Option<SyntheticData>, privacy_unit: PrivacyUnit, dp_parameters: DpParameters ) -> Result<RelationWithDpEvent>
Rewrite the query so that it is differentially private.
source§impl Relation
impl Relation
pub fn uniform_adjustment<'a>(&'a self, weight: f64) -> RelationWithWeight
pub fn differenciated_adjustment<'a>( &'a self, relations: &'a Hierarchy<Arc<Relation>>, tables_and_weights: Vec<(Vec<String>, f64)> ) -> RelationWithWeight
pub fn uniform_poisson_sampling<'a>(&'a self, proba: f64) -> Relation
pub fn differenciated_poisson_sampling<'a>( &'a self, relations: &'a Hierarchy<Arc<Relation>>, tables_and_sampling_probabilities: Vec<(Vec<String>, f64)> ) -> Relation
pub fn uniform_sampling_without_replacements<'a>( &'a self, rate: f64, rate_multiplier: f64 ) -> Relation
Trait Implementations§
source§impl<'a> Acceptor<'a> for Relation
impl<'a> Acceptor<'a> for Relation
Implement the Acceptor trait
source§fn dependencies(&'a self) -> Dependencies<'a, Self>
fn dependencies(&'a self) -> Dependencies<'a, Self>
fn accept<O: Clone, V: Visitor<'a, Self, O>>(&'a self, visitor: V) -> O
fn iter(&'a self) -> Iter<'a, Self>
fn iter_with<O: Clone, V: Visitor<'a, Self, O>>( &'a self, visitor: V ) -> IterWith<'a, O, Self, V>
source§impl DataTyped for Relation
impl DataTyped for Relation
source§fn has_data_type(&self, data_type: &DataType) -> bool
fn has_data_type(&self, data_type: &DataType) -> bool
source§fn is_contained_by(&self, data_type: &DataType) -> bool
fn is_contained_by(&self, data_type: &DataType) -> bool
source§impl From<DpRelation> for Relation
impl From<DpRelation> for Relation
source§fn from(value: DpRelation) -> Self
fn from(value: DpRelation) -> Self
source§impl From<PupRelation> for Relation
impl From<PupRelation> for Relation
source§fn from(value: PupRelation) -> Self
fn from(value: PupRelation) -> Self
source§impl From<Relation> for SDRelation
impl From<Relation> for SDRelation
source§impl From<SDRelation> for Relation
impl From<SDRelation> for Relation
source§fn from(value: SDRelation) -> Self
fn from(value: SDRelation) -> Self
source§impl<'a> IntoIterator for &'a Relation
impl<'a> IntoIterator for &'a Relation
source§impl PartialEq for Relation
impl PartialEq for Relation
source§impl Ready<Relation> for TableBuilder<WithSchema>
impl Ready<Relation> for TableBuilder<WithSchema>
source§impl Ready<Relation> for ValuesBuilder
impl Ready<Relation> for ValuesBuilder
source§impl<'a, T: QueryToRelationTranslator + Copy + Clone> TryFrom<(QueryWithRelations<'a>, T)> for Relation
impl<'a, T: QueryToRelationTranslator + Copy + Clone> TryFrom<(QueryWithRelations<'a>, T)> for Relation
source§impl<'a> TryFrom<QueryWithRelations<'a>> for Relation
impl<'a> TryFrom<QueryWithRelations<'a>> for Relation
source§impl TryFrom<Relation> for PupRelation
impl TryFrom<Relation> for PupRelation
source§impl Variant for Relation
impl Variant for Relation
source§fn input_hierarchy(&self) -> Hierarchy<&Relation>
fn input_hierarchy(&self) -> Hierarchy<&Relation>
impl Eq for Relation
impl StructuralPartialEq for Relation
Auto Trait Implementations§
impl Freeze for Relation
impl !RefUnwindSafe for Relation
impl Send for Relation
impl Sync for Relation
impl Unpin for Relation
impl !UnwindSafe for Relation
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moresource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.