From 0ef6f1f73948c581a8479d26bf40824d733f2a03 Mon Sep 17 00:00:00 2001 From: Arnaud Mimart <33665250+amimart@users.noreply.github.com> Date: Mon, 22 May 2023 17:56:55 +0200 Subject: [PATCH] feat(cognitarium): build query plan from basic graph pattern --- .../src/querier/plan_builder.rs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/contracts/okp4-cognitarium/src/querier/plan_builder.rs b/contracts/okp4-cognitarium/src/querier/plan_builder.rs index b18f3eb7..93195ce0 100644 --- a/contracts/okp4-cognitarium/src/querier/plan_builder.rs +++ b/contracts/okp4-cognitarium/src/querier/plan_builder.rs @@ -26,6 +26,27 @@ impl<'a> PlanBuilder<'a> { pub fn build_plan(&mut self, where_clause: WhereClause) -> StdResult { Err(StdError::generic_err("not implemented")) + fn build_from_bgp(&self, bgp: Vec) -> StdResult { + 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,