diff --git a/contracts/okp4-cognitarium/src/contract.rs b/contracts/okp4-cognitarium/src/contract.rs index 89f98ba0..c422cf3a 100644 --- a/contracts/okp4-cognitarium/src/contract.rs +++ b/contracts/okp4-cognitarium/src/contract.rs @@ -140,7 +140,7 @@ pub mod execute { .collect::>>()? } else { query_engine - .construct_triples(plan, delete_templates)? + .construct_triples(plan, delete_templates) .collect::>>()? }; diff --git a/contracts/okp4-cognitarium/src/querier/engine.rs b/contracts/okp4-cognitarium/src/querier/engine.rs index 834a90cc..c48d8d80 100644 --- a/contracts/okp4-cognitarium/src/querier/engine.rs +++ b/contracts/okp4-cognitarium/src/querier/engine.rs @@ -66,31 +66,28 @@ impl<'a> QueryEngine<'a> { .map(|t| AtomTemplate::try_new(&plan, prefixes, t)) .collect::>>()?; - ResolvedAtomIterator::try_new( + Ok(ResolvedAtomIterator::new( self.storage, ns_cache.into(), IdentifierIssuer::new("b", 0u128), self.eval_plan(plan), templates, - ) + )) } pub fn construct_triples( &'a self, plan: QueryPlan, templates: Vec, - ) -> StdResult> { - ResolvedTripleIterator::try_new(self.eval_plan(plan), templates) + ) -> ResolvedTripleIterator<'_> { + ResolvedTripleIterator::new(self.eval_plan(plan), templates) } pub fn make_triple_templates( &'a self, plan: &QueryPlan, prefixes: &HashMap, - templates: Either< - Vec<(VarOrNode, VarOrNamedNode, VarOrNodeOrLiteral)>, - Vec<(VarOrNamedNode, VarOrNamedNode, VarOrNamedNodeOrLiteral)>, - >, + templates: Either, Vec>, ns_cache: Vec, ) -> StdResult> { let mut ns_resolver: NamespaceResolver = ns_cache.into(); @@ -536,15 +533,15 @@ pub struct ResolvedTripleIterator<'a> { } impl<'a> ResolvedTripleIterator<'a> { - pub fn try_new( + pub fn new( upstream_iter: ResolvedVariablesIterator<'a>, templates: Vec, - ) -> StdResult { - Ok(Self { + ) -> Self { + Self { upstream_iter, templates, buffer: VecDeque::new(), - }) + } } } @@ -590,16 +587,16 @@ pub struct TripleTemplate { object: Either, } +pub type TripleTemplateWithBlankNode = (VarOrNode, VarOrNamedNode, VarOrNodeOrLiteral); +pub type TripleTemplateNoBlankNode = (VarOrNamedNode, VarOrNamedNode, VarOrNamedNodeOrLiteral); + impl TripleTemplate { fn try_new( storage: &dyn Storage, ns_resolver: &mut NamespaceResolver, plan: &QueryPlan, prefixes: &HashMap, - template: Either< - (VarOrNode, VarOrNamedNode, VarOrNodeOrLiteral), - (VarOrNamedNode, VarOrNamedNode, VarOrNamedNodeOrLiteral), - >, + template: Either, ) -> StdResult { let (s_tpl, p_tpl, o_tpl) = match template { Right((s, p, o)) => (Right(s), p, Right(o)), @@ -759,21 +756,21 @@ pub struct ResolvedAtomIterator<'a> { } impl<'a> ResolvedAtomIterator<'a> { - pub fn try_new( + pub fn new( storage: &'a dyn Storage, ns_resolver: NamespaceResolver, id_issuer: IdentifierIssuer, upstream_iter: ResolvedVariablesIterator<'a>, templates: Vec, - ) -> StdResult { - Ok(Self { + ) -> Self { + Self { storage, ns_resolver, id_issuer, upstream_iter, templates, buffer: VecDeque::new(), - }) + } } } diff --git a/contracts/okp4-cognitarium/src/querier/plan_builder.rs b/contracts/okp4-cognitarium/src/querier/plan_builder.rs index baee369f..0d36e466 100644 --- a/contracts/okp4-cognitarium/src/querier/plan_builder.rs +++ b/contracts/okp4-cognitarium/src/querier/plan_builder.rs @@ -5,7 +5,7 @@ use crate::msg::{ use crate::querier::mapper::{iri_as_node, literal_as_object}; use crate::querier::plan::{PatternValue, PlanVariable, QueryNode, QueryPlan}; use crate::state::{HasCachedNamespaces, Namespace, NamespaceResolver, Object, Predicate, Subject}; -use cosmwasm_std::{StdError, StdResult, Storage}; +use cosmwasm_std::{StdResult, Storage}; use std::collections::HashMap; pub struct PlanBuilder<'a> { @@ -480,7 +480,12 @@ mod test { None, None, vec![], - Err(StdError::generic_err("Empty basic graph pattern")), + Ok(QueryPlan { + entrypoint: QueryNode::Noop { + bound_variables: vec![], + }, + variables: vec![], + }), ), ( None,