Skip to content

Commit

Permalink
feat(cognitarium): build query plan from basic graph pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart committed Jun 5, 2023
1 parent 7f32451 commit 0ef6f1f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions contracts/okp4-cognitarium/src/querier/plan_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,27 @@ impl<'a> PlanBuilder<'a> {
pub fn build_plan(&mut self, where_clause: WhereClause) -> StdResult<QueryPlan> {
Err(StdError::generic_err("not implemented"))

fn build_from_bgp(&self, bgp: Vec<QueryNode::TriplePattern>) -> StdResult<QueryPlan> {
bgp.iter()
.reduce(|left: QueryNode, right: QueryNode| -> QueryNode {
if left
.bound_variables()
.union(&right.bound_variables())
.next()
.is_some()
{
return QueryNode::ForLoopJoin { left, right };
}
QueryNode::CartesianProductJoin { left, right }
})
.map(Ok)
.unwrap_or(Err(StdError::generic_err("Empty basic graph pattern")))
.map(|query_node: QueryNode| QueryPlan {
entrypoint: query_node,
variables: self.variables.clone(),
})
}

fn build_triple_pattern(
&mut self,
pattern: &TriplePattern,
Expand Down

0 comments on commit 0ef6f1f

Please sign in to comment.