Skip to content

Commit

Permalink
feat(cognitarium): introduce query plan model
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Jun 5, 2023
1 parent cb7a159 commit 3a074be
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions contracts/okp4-cognitarium/src/querier/plan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use crate::msg::{Prefix, SelectQuery, SimpleWhereCondition, TriplePattern, WhereCondition};
use crate::state::{Object, Predicate, Subject};
use std::collections::{BTreeMap, BTreeSet, HashMap};

/// Represents a querying plan.
pub struct QueryPlan {
/// References the ending node of the plan, when evaluated others nodes will be invoked in
/// cascade.
pub entrypoint: QueryNode,

/// Contains all the query variables, their index in this array are internally used as
/// identifiers.
pub variables: Vec<String>,
}

/// Represents a single part of the query plan processing. Each node is intended to provide a
/// specific behavior given an evaluation context.
pub enum QueryNode {
/// Match the triple pattern against the state. The triple elements can be either a variable or
/// a constant value, in the case of a variable it'll be either provided by the context of
/// previous evaluation or calculated and present in output.
TriplePattern {
subject: PatternValue<Subject>,
predicate: PatternValue<Predicate>,
object: PatternValue<Object>,
},

/// Join two nodes by applying the cartesian product of the nodes variables.
///
/// This should be used when the nodes doesn't have variables in common, and can be seen as a
/// full join of disjoint datasets.
CartesianProductJoin { left: Self, right: Self },

/// Join two nodes by using the variables values from the left node as replacement in the right
/// node.
///
/// This results to an inner join, but the underlying processing stream the variables from the
/// left node to use them as right node values.
ForLoopJoin { left: Self, right: Self },

/// Skip the specified first elements from the child node.
Skip { child: Self, first: usize },

/// Limit to the specified first elements from the child node.
Limit { child: Self, first: usize },
}

pub enum PatternValue<V> {
Constant(V),
Variable(usize),
}

0 comments on commit 3a074be

Please sign in to comment.