Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cognitarium)!: add query expression filters #616

Merged
merged 15 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading