Skip to content

Commit

Permalink
feat(cognitarium): implements query engine main logic
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Jun 5, 2023
1 parent b57e3a0 commit ee8254b
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion contracts/okp4-cognitarium/src/querier/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,28 @@ impl<'a> QueryEngine<'a> {
}

pub fn eval_plan(&self, plan: QueryPlan) -> ResolvedVariablesIterator {
Box::new(iter::empty())
return self.eval_node(plan.entrypoint)(ResolvedVariables::with_capacity(
plan.variables.len(),
));
}

fn eval_node(
&self,
node: QueryNode,
) -> Box<dyn Fn(ResolvedVariables) -> ResolvedVariablesIterator> {
match node {
QueryNode::TriplePattern {
subject,
predicate,
object,
} => Box::new(move |_| Box::new(iter::empty())),
QueryNode::CartesianProductJoin { left, right } => {
Box::new(move |_| Box::new(iter::empty()))
}
QueryNode::ForLoopJoin { left, right } => Box::new(move |_| Box::new(iter::empty())),
QueryNode::Skip { child, first } => Box::new(move |_| Box::new(iter::empty())),
QueryNode::Limit { child, first } => Box::new(move |_| Box::new(iter::empty())),
}
}
}

Expand All @@ -30,3 +51,14 @@ pub enum ResolvedVariable {
pub struct ResolvedVariables {
pub variables: Vec<Option<ResolvedVariable>>,
}

impl ResolvedVariables {
pub fn with_capacity(cap: usize) -> Self {
let mut variables = Vec::with_capacity(cap);
for i in 0..usize {
variables.insert(i, None);
}

Self { variables }
}
}

0 comments on commit ee8254b

Please sign in to comment.