Skip to main content

AggregateBody

Struct AggregateBody 

Source
pub struct AggregateBody {
    pub result_var: VariableSymbol,
    pub aggregator: Aggregator,
    pub input_var: VariableSymbol,
    pub group_by: Vec<VariableSymbol>,
    pub inner_body: Vec<Literal>,
}
Expand description

An aggregation sub-query inside a rule body.

Semantically equivalent to a SPARQL Group { ... } over { ... } projection: evaluate inner_body as a sub-query, group the results by group_by, fold each group’s input_var values with aggregator, and bind the per-group result to result_var. The aggregate then participates in the outer rule body as if result_var were produced by a positive atom that ranges over the per-group results.

§Variable scoping

inner_body is its own scope: positive atoms and BIND outputs inside the inner body bind variables that are visible only within the aggregation. The three sets of variables that leak out are group_by, input_var, and (after the aggregation fires) result_var. Concretely:

  • group_by and input_var MUST be bound by some positive atom or BIND inside inner_body.
  • result_var MUST be fresh — it must not appear anywhere else in the outer rule (head or body).

§Inner-body literal kinds

inner_body accepts the same four literal kinds the outer rule body accepts — Literal::Positive, Literal::Negative, Literal::Filter, and Literal::Bind — under the usual safety rules (negated atoms and filter expressions reference only inner-body-bound variables; BIND expressions reference only earlier inner positives / binds and bind a fresh variable). Nested aggregates inside an aggregate’s inner body are rejected at validation time as super::error::ProgramValidationError::NestedAggregateInInnerBody.

Fields§

§result_var: VariableSymbol

The variable that receives the per-group aggregate result.

§aggregator: Aggregator

Which aggregator to apply.

§input_var: VariableSymbol

The variable whose values are folded into the aggregate (the “input expression” in SPARQL terms).

§group_by: Vec<VariableSymbol>

Group-by keys. The aggregator runs once per distinct tuple of group_by values; an empty group_by collapses every inner-body binding into a single group.

§inner_body: Vec<Literal>

Literals forming the aggregation’s inner sub-query. Accepts Literal::Positive, Literal::Negative, Literal::Filter, and Literal::Bind under the per-kind safety rules. Nested Literal::Aggregate is rejected at validation time.

Implementations§

Source§

impl AggregateBody

Source

pub fn inner_bound_variables(&self) -> BTreeSet<VariableSymbol>

Variables bound by the inner body — every variable a positive inner atom binds, plus every BIND’s output variable. Used by safety analysis to verify that input_var and group_by are sourced from the inner body and that inner negation / filter / bind references stay within the inner scope.

Source

pub fn exported_variables(&self) -> BTreeSet<VariableSymbol>

Variables this aggregate exposes to the outer rule body: the freshly-bound result_var plus every key the outer rule groups by. The outer-scope view of an aggregate body literal.

Source

pub fn contains_nested_aggregate(&self) -> bool

Returns true when the inner body contains a nested Literal::Aggregate. Nested aggregates are rejected as super::error::ProgramValidationError::NestedAggregateInInnerBody.

Trait Implementations§

Source§

impl Clone for AggregateBody

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for AggregateBody

Source§

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

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

impl Eq for AggregateBody

Source§

impl Hash for AggregateBody

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 PartialEq for AggregateBody

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for AggregateBody

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

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

Source§

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.