Skip to content

Commit

Permalink
Merge pull request #616 from axone-protocol/feat/cognitarium-expr-eval
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart authored Aug 23, 2024
2 parents 3f79933 + dcc7155 commit 844a8b9
Show file tree
Hide file tree
Showing 17 changed files with 1,827 additions and 638 deletions.
445 changes: 225 additions & 220 deletions contracts/axone-cognitarium/src/contract.rs

Large diffs are not rendered by default.

72 changes: 51 additions & 21 deletions contracts/axone-cognitarium/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ pub enum ExecuteMsg {
/// The prefixes used in the operation.
prefixes: Vec<Prefix>,
/// Specifies the specific triple templates to delete.
/// If nothing is provided, the patterns from the `where` clause are used for deletion.
/// If nothing is provided and the `where` clause is a single Bgp, the patterns are used for
/// deletion.
delete: Vec<TripleDeleteTemplate>,
/// Defines the patterns that data (RDF triples) should match in order for it to be
/// considered for deletion.
r#where: WhereClause,
/// considered for deletion, if any.
r#where: Option<WhereClause>,
},
}

Expand Down Expand Up @@ -424,7 +425,7 @@ pub struct DescribeQuery {
pub resource: VarOrNamedNode,
/// The WHERE clause.
/// This clause is used to specify the resource identifier to describe using variable bindings.
pub r#where: WhereClause,
pub r#where: Option<WhereClause>,
}

/// # ConstructQuery
Expand All @@ -435,7 +436,8 @@ pub struct ConstructQuery {
/// The prefixes used in the query.
pub prefixes: Vec<Prefix>,
/// The triples to construct.
/// If nothing is provided, the patterns from the `where` clause are used for construction.
/// If nothing is provided and the `where` clause is a single Bgp, the patterns are used for
/// construction.
pub construct: Vec<TripleConstructTemplate>,
/// The WHERE clause.
/// This clause is used to specify the triples to construct using variable bindings.
Expand All @@ -462,26 +464,54 @@ pub enum SelectItem {
}

/// # WhereClause
/// Represents a WHERE clause in a [SelectQuery], i.e. a set of conditions to filter the results.
pub type WhereClause = Vec<WhereCondition>;

/// # WhereCondition
/// Represents a condition in a [WhereClause].
/// Represents a WHERE clause, i.e. a set of conditions to filter the results.
#[cw_serde]
pub enum WhereCondition {
/// # Simple
/// Represents a simple condition.
Simple(SimpleWhereCondition),
pub enum WhereClause {
/// # Bgp
/// Represents a basic graph pattern expressed as a set of triple patterns.
Bgp { patterns: Vec<TriplePattern> },

/// # LateralJoin
/// Evaluates right for all result row of left
LateralJoin { left: Box<Self>, right: Box<Self> },

/// # Filter
/// Filters the inner clause matching the expression.
/// The solutions coming from the inner clause that do not match the expression are discarded.
/// The variables provided in the inner clause are available in the filter expression.
Filter { expr: Expression, inner: Box<Self> },
}

/// # SimpleWhereCondition
/// Represents a simple condition in a [WhereCondition].
/// # Expression
/// Represents a logical combination of operations whose evaluation results in a term.
#[cw_serde]
pub enum SimpleWhereCondition {
/// # TriplePattern
/// Represents a triple pattern, i.e. a condition on a triple based on its subject, predicate and
/// object.
TriplePattern(TriplePattern),
pub enum Expression {
/// A named node constant.
NamedNode(IRI),
/// A literal constant.
Literal(Literal),
/// A variable that must be bound for evaluation.
Variable(String),
/// Logical conjunction of expressions.
/// All expressions must evaluate to true for the conjunction to be true.
/// If the conjunction is empty, it is considered true.
And(Vec<Self>),
/// Logical disjunction of expressions.
/// At least one expression must evaluate to true for the disjunction to be true.
/// If the disjunction is empty, it is considered false.
Or(Vec<Self>),
/// Equality comparison.
Equal(Box<Self>, Box<Self>),
/// Greater than comparison.
Greater(Box<Self>, Box<Self>),
/// Greater or equal comparison.
GreaterOrEqual(Box<Self>, Box<Self>),
/// Less than comparison.
Less(Box<Self>, Box<Self>),
/// Less or equal comparison.
LessOrEqual(Box<Self>, Box<Self>),
/// Negation of an expression.
Not(Box<Self>),
}

/// # TripleDeleteTemplate
Expand Down
Loading

0 comments on commit 844a8b9

Please sign in to comment.