Enum qrlew::relation::Relation

source ·
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§

§

Table(Table)

§

Map(Map)

§

Reduce(Reduce)

§

Join(Join)

§

Set(Set)

§

Values(Values)

Implementations§

source§

impl Relation

source

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

source

pub fn privacy_unit_row(self) -> Self

Add the field for the row privacy

source

pub fn privacy_unit(self, referred_field: &str) -> Self

Add the field containing the privacy unit

source

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

source

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

source

pub fn dot<W: Write>(&self, w: &mut W, opts: &[&str]) -> Result<()>

Render the Relation to dot

source§

impl Relation

source

pub fn with_name(self, name: String) -> Relation

Rename a Relation

source

pub fn identity_with_field(self, name: &str, expr: Expr) -> Relation

Add a field that derives from existing fields

source

pub fn identity_insert_field( self, index: usize, inserted_name: &str, inserted_expr: Expr ) -> Relation

Insert a field that derives from existing fields

source

pub fn with_field(self, name: &str, expr: Expr) -> Relation

Add a field that derives from input fields

source

pub fn insert_field( self, index: usize, inserted_name: &str, inserted_expr: Expr ) -> Relation

Insert a field that derives from input fields

source

pub fn filter_fields<P: Fn(&str) -> bool>(self, predicate: P) -> Relation

Filter fields

source

pub fn map_fields<F: Fn(&str, Expr) -> Expr>(self, f: F) -> Relation

Map fields

source

pub fn rename_fields<F: Fn(&str, &Expr) -> String>(self, f: F) -> Relation

Rename fields

source

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 the values parameter.
source

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

source

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

source

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 by scale_factors Relation
source

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

source

pub fn add_gaussian_noise(self, name_sigmas: &[(&str, f64)]) -> Relation

Add gaussian noise of a given standard deviation to the given columns

source

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

source

pub fn filter(self, predicate: Expr) -> Relation

Returns a Relation::Map that inputs self and filter by predicate

source

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)

source

pub fn poisson_sampling(self, proba: f64) -> Relation

Poisson sampling of a relation. It samples each line with probability 0 <= proba <= 1

source

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

source

pub fn distinct(self) -> Relation

GROUP BY all the fields. This mimicks the sql DISTINCT in the SELECT clause.

source

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.

source

pub fn public_values_column(&self, col_name: &str) -> Result<Relation>

source

pub fn public_values(&self) -> Result<Relation>

source

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

source

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

source

pub fn inputs(&self) -> Vec<&Relation>

source

pub fn input_schemas(&self) -> Vec<&Schema>

source

pub fn input_fields(&self) -> Vec<&Field>

source

pub fn table() -> TableBuilder<WithoutSchema>

Build a table

source

pub fn map() -> MapBuilder<WithoutInput>

Build a map

source

pub fn reduce() -> ReduceBuilder<WithoutInput>

Build a reduce

source

pub fn join() -> JoinBuilder<WithoutInput, WithoutInput>

Build a reduce

source

pub fn set() -> SetBuilder<WithoutInput, WithoutInput>

Build a reduce

source

pub fn values() -> ValuesBuilder

Build a values

source§

impl Relation

source

pub fn with_attributes<'a, Attributes: Clone>( &'a self, attributes: Attributes ) -> RelationWithAttributes<'a, Attributes>

Add attributes to Relation

source

pub fn with_default_attributes<'a, Attributes: Clone + Default>( &'a self ) -> RelationWithAttributes<'a, Attributes>

Add attributes to Relation

source§

impl Relation

source

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

source

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

source

pub fn compose<'a>( &'a self, relations: &'a Hierarchy<Arc<Relation>> ) -> Relation

source§

impl Relation

source

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.

source

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

source

pub fn uniform_adjustment<'a>(&'a self, weight: f64) -> RelationWithWeight

source

pub fn differenciated_adjustment<'a>( &'a self, relations: &'a Hierarchy<Arc<Relation>>, tables_and_weights: Vec<(Vec<String>, f64)> ) -> RelationWithWeight

source

pub fn uniform_poisson_sampling<'a>(&'a self, proba: f64) -> Relation

source

pub fn differenciated_poisson_sampling<'a>( &'a self, relations: &'a Hierarchy<Arc<Relation>>, tables_and_sampling_probabilities: Vec<(Vec<String>, f64)> ) -> Relation

source

pub fn uniform_sampling_without_replacements<'a>( &'a self, rate: f64, rate_multiplier: f64 ) -> Relation

Trait Implementations§

source§

impl<'a> Acceptor<'a> for Relation

Implement the Acceptor trait

source§

fn dependencies(&'a self) -> Dependencies<'a, Self>

All the sub-objects to visit
source§

fn accept<O: Clone, V: Visitor<'a, Self, O>>(&'a self, visitor: V) -> O

source§

fn iter(&'a self) -> Iter<'a, Self>

source§

fn iter_with<O: Clone, V: Visitor<'a, Self, O>>( &'a self, visitor: V ) -> IterWith<'a, O, Self, V>

source§

impl Clone for Relation

source§

fn clone(&self) -> Relation

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl DataTyped for Relation

source§

fn data_type(&self) -> DataType

Return the DataType atached to the object
source§

fn has_data_type(&self, data_type: &DataType) -> bool

Return whether the object has exactly the given type
source§

fn is_contained_by(&self, data_type: &DataType) -> bool

Return whether the object has a type contained in the given type
source§

impl Debug for Relation

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Display for Relation

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Dot for Relation

source§

impl From<&Relation> for Query

Based on the FromRelationVisitor implement the From trait

source§

fn from(value: &Relation) -> Self

Converts to this type from the input type.
source§

impl From<DpRelation> for Relation

source§

fn from(value: DpRelation) -> Self

Converts to this type from the input type.
source§

impl From<Join> for Relation

source§

fn from(v: Join) -> Self

Converts to this type from the input type.
source§

impl From<Map> for Relation

source§

fn from(v: Map) -> Self

Converts to this type from the input type.
source§

impl From<PupRelation> for Relation

source§

fn from(value: PupRelation) -> Self

Converts to this type from the input type.
source§

impl From<Reduce> for Relation

source§

fn from(v: Reduce) -> Self

Converts to this type from the input type.
source§

impl From<Relation> for SDRelation

source§

fn from(value: Relation) -> Self

Converts to this type from the input type.
source§

impl From<SDRelation> for Relation

source§

fn from(value: SDRelation) -> Self

Converts to this type from the input type.
source§

impl From<Set> for Relation

source§

fn from(v: Set) -> Self

Converts to this type from the input type.
source§

impl From<Table> for Relation

source§

fn from(v: Table) -> Self

Converts to this type from the input type.
source§

impl From<Values> for Relation

source§

fn from(v: Values) -> Self

Converts to this type from the input type.
source§

impl Hash for Relation

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Index<usize> for Relation

§

type Output = Field

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl<'a> IntoIterator for &'a Relation

§

type Item = &'a Relation

The type of the elements being iterated over.
§

type IntoIter = FilterMap<Iterator<'a, &'a Relation, Identity, Relation>, fn(_: (&'a Relation, State<&'a Relation>)) -> Option<&'a Relation>>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq for Relation

source§

fn eq(&self, other: &Relation) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Ready<Relation> for JoinBuilder<WithInput, WithInput>

§

type Error = Error

source§

fn try_build(self) -> Result<Relation>

Try to build
source§

fn build(self) -> Output

Build and panic in case of error
source§

impl Ready<Relation> for MapBuilder<WithInput>

§

type Error = Error

source§

fn try_build(self) -> Result<Relation>

Try to build
source§

fn build(self) -> Output

Build and panic in case of error
source§

impl Ready<Relation> for ReduceBuilder<WithInput>

§

type Error = Error

source§

fn try_build(self) -> Result<Relation>

Try to build
source§

fn build(self) -> Output

Build and panic in case of error
source§

impl Ready<Relation> for SetBuilder<WithInput, WithInput>

§

type Error = Error

source§

fn try_build(self) -> Result<Relation>

Try to build
source§

fn build(self) -> Output

Build and panic in case of error
source§

impl Ready<Relation> for TableBuilder<WithSchema>

§

type Error = Error

source§

fn try_build(self) -> Result<Relation>

Try to build
source§

fn build(self) -> Output

Build and panic in case of error
source§

impl Ready<Relation> for ValuesBuilder

§

type Error = Error

source§

fn try_build(self) -> Result<Relation>

Try to build
source§

fn build(self) -> Output

Build and panic in case of error
source§

impl<'a, T: QueryToRelationTranslator + Copy + Clone> TryFrom<(QueryWithRelations<'a>, T)> for Relation

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: (QueryWithRelations<'a>, T)) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a> TryFrom<QueryWithRelations<'a>> for Relation

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: QueryWithRelations<'a>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl TryFrom<Relation> for Join

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(relation: Relation) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Relation> for Map

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(relation: Relation) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Relation> for PupRelation

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(value: Relation) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Relation> for Reduce

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(relation: Relation) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Relation> for Set

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(relation: Relation) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Relation> for Table

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(relation: Relation) -> Result<Self>

Performs the conversion.
source§

impl TryFrom<Relation> for Values

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(relation: Relation) -> Result<Self>

Performs the conversion.
source§

impl Variant for Relation

source§

fn name(&self) -> &str

Return the name
source§

fn schema(&self) -> &Schema

Return the Schema
source§

fn size(&self) -> &Integer

Return the size bounds
source§

fn inputs(&self) -> Vec<&Relation>

Return the inputs
source§

fn input_hierarchy(&self) -> Hierarchy<&Relation>

Return the input hierarchy
source§

fn fields(&self) -> Vec<&Field>

Return the fields
source§

fn field_from_index(&self, index: usize) -> Result<&Field>

Access a field of the Relation by index
source§

impl With<(&str, Expr)> for Relation

source§

fn with(self, (name, expr): (&str, Expr)) -> Self

source§

impl Eq for Relation

source§

impl StructuralPartialEq for Relation

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<'a, T, V> Visitor<'a, Relation, T> for V
where T: Clone, V: Visitor<'a, T>,

source§

fn visit( &self, acceptor: &'a Relation, dependencies: Visited<'a, Relation, T> ) -> T

A function called on each node of a structured object with its dependencies already visited
source§

fn dependencies(&self, acceptor: &'a A) -> Dependencies<'a, A>

Describe the dependencies of the acceptor The dependencies can be customized
source§

impl<Input, W> WithIterator<Input> for W
where W: With<Input>,

source§

fn with_iter<I>(self, iter: I) -> W
where I: IntoIterator<Item = Input>,

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Scalar for T
where T: 'static + Clone + PartialEq + Debug,