diff --git a/lib/src/sparql/dataset.rs b/lib/src/sparql/dataset.rs index 8275b480..77871ee3 100644 --- a/lib/src/sparql/dataset.rs +++ b/lib/src/sparql/dataset.rs @@ -1,8 +1,7 @@ use crate::sparql::algebra::QueryDataset; use crate::sparql::EvaluationError; use crate::store::numeric_encoder::{ - EncodedQuad, EncodedTerm, ReadEncoder, StrContainer, StrEncodingAware, StrHash, StrId, - StrLookup, + EncodedQuad, EncodedTerm, ReadEncoder, StrContainer, StrEncodingAware, StrHash, StrLookup, }; use crate::store::ReadableEncodedStore; use std::cell::RefCell; @@ -12,7 +11,7 @@ use std::iter::{empty, once, Once}; pub(crate) struct DatasetView { store: S, extra: RefCell>, - dataset: EncodedDatasetSpec, + dataset: EncodedDatasetSpec, } impl DatasetView { @@ -50,27 +49,68 @@ impl DatasetView { }) } + fn store_encoded_quads_for_pattern( + &self, + subject: Option, + predicate: Option, + object: Option, + graph_name: Option, + ) -> impl Iterator> + 'static { + self.store + .encoded_quads_for_pattern(subject, predicate, object, graph_name) + .map(|t| t.map_err(|e| e.into())) + } +} + +impl StrEncodingAware for DatasetView { + type Error = EvaluationError; +} + +impl StrLookup for DatasetView { + fn get_str(&self, id: StrHash) -> Result, EvaluationError> { + self.extra + .borrow() + .get(&id) + .cloned() + .map(Ok) + .or_else(|| self.store.get_str(id).map_err(|e| e.into()).transpose()) + .transpose() + } + + fn get_str_id(&self, value: &str) -> Result, EvaluationError> { + let id = StrHash::new(value); + Ok(if self.extra.borrow().contains_key(&id) { + Some(id) + } else { + self.store.get_str_id(value).map_err(|e| e.into())? + }) + } +} + +impl ReadableEncodedStore for DatasetView { + type QuadsIter = Box>>; + type GraphsIter = Once>; + #[allow(clippy::needless_collect)] - fn encoded_quads_for_pattern_in_dataset( + fn encoded_quads_for_pattern( &self, - subject: Option>, - predicate: Option>, - object: Option>, - graph_name: Option>, - ) -> Box>, EvaluationError>>> - { + subject: Option, + predicate: Option, + object: Option, + graph_name: Option, + ) -> Box>> { if let Some(graph_name) = graph_name { if graph_name.is_default_graph() { if let Some(default_graph_graphs) = &self.dataset.default { if default_graph_graphs.len() == 1 { // Single graph optimization Box::new( - map_iter(self.store.encoded_quads_for_pattern( + self.store_encoded_quads_for_pattern( subject, predicate, object, Some(default_graph_graphs[0]), - )) + ) .map(|quad| { let quad = quad?; Ok(EncodedQuad::new( @@ -85,7 +125,7 @@ impl DatasetView { let iters = default_graph_graphs .iter() .map(|graph_name| { - self.store.encoded_quads_for_pattern( + self.store_encoded_quads_for_pattern( subject, predicate, object, @@ -93,7 +133,7 @@ impl DatasetView { ) }) .collect::>(); - Box::new(map_iter(iters.into_iter().flatten()).map(|quad| { + Box::new(iters.into_iter().flatten().map(|quad| { let quad = quad?; Ok(EncodedQuad::new( quad.subject, @@ -104,10 +144,7 @@ impl DatasetView { })) } } else { - Box::new(map_iter( - self.store - .encoded_quads_for_pattern(subject, predicate, object, None), - )) + Box::new(self.store_encoded_quads_for_pattern(subject, predicate, object, None)) } } else if self .dataset @@ -115,12 +152,12 @@ impl DatasetView { .as_ref() .map_or(true, |d| d.contains(&graph_name)) { - Box::new(map_iter(self.store.encoded_quads_for_pattern( + Box::new(self.store_encoded_quads_for_pattern( subject, predicate, object, Some(graph_name), - ))) + )) } else { Box::new(empty()) } @@ -128,7 +165,7 @@ impl DatasetView { let iters = named_graphs .iter() .map(|graph_name| { - self.store.encoded_quads_for_pattern( + self.store_encoded_quads_for_pattern( subject, predicate, object, @@ -136,70 +173,17 @@ impl DatasetView { ) }) .collect::>(); - Box::new(map_iter(iters.into_iter().flatten())) + Box::new(iters.into_iter().flatten()) } else { Box::new( - map_iter( - self.store - .encoded_quads_for_pattern(subject, predicate, object, None), - ) - .filter(|quad| match quad { - Err(_) => true, - Ok(quad) => quad.graph_name != EncodedTerm::DefaultGraph, - }), + self.store_encoded_quads_for_pattern(subject, predicate, object, None) + .filter(|quad| match quad { + Err(_) => true, + Ok(quad) => quad.graph_name != EncodedTerm::DefaultGraph, + }), ) } } -} - -impl StrEncodingAware for DatasetView { - type Error = EvaluationError; - type StrId = DatasetStrId; -} - -impl StrLookup for DatasetView { - fn get_str(&self, id: DatasetStrId) -> Result, EvaluationError> { - match id { - DatasetStrId::Store(id) => self.store.get_str(id).map_err(|e| e.into()), - DatasetStrId::Temporary(id) => Ok(self.extra.borrow().get(&id).cloned()), - } - } - - fn get_str_id(&self, value: &str) -> Result>, EvaluationError> { - let id = StrHash::new(value); - if self.extra.borrow().contains_key(&id) { - Ok(Some(DatasetStrId::Temporary(id))) - } else { - Ok(self - .store - .get_str_id(value) - .map_err(|e| e.into())? - .map(DatasetStrId::Store)) - } - } -} - -impl ReadableEncodedStore for DatasetView { - type QuadsIter = - Box>, EvaluationError>>>; - type GraphsIter = Once>, EvaluationError>>; - - fn encoded_quads_for_pattern( - &self, - subject: Option>, - predicate: Option>, - object: Option>, - graph_name: Option>, - ) -> Box>, EvaluationError>>> - { - if let Some((subject, predicate, object, graph_name)) = - try_map_quad_pattern(subject, predicate, object, graph_name) - { - self.encoded_quads_for_pattern_in_dataset(subject, predicate, object, graph_name) - } else { - Box::new(empty()) - } - } fn encoded_named_graphs(&self) -> Self::GraphsIter { once(Err(EvaluationError::msg( @@ -207,90 +191,29 @@ impl ReadableEncodedStore for DatasetView { ))) } - fn contains_encoded_named_graph( - &self, - _: EncodedTerm, - ) -> Result { + fn contains_encoded_named_graph(&self, _: EncodedTerm) -> Result { Err(EvaluationError::msg( "Graphs lookup is not implemented by DatasetView", )) } } -fn map_iter<'a, I: StrId>( - iter: impl Iterator, impl Into>> + 'a, -) -> impl Iterator>, EvaluationError>> + 'a { - iter.map(|t| { - t.map(|q| EncodedQuad { - subject: q.subject.map_id(DatasetStrId::Store), - predicate: q.predicate.map_id(DatasetStrId::Store), - object: q.object.map_id(DatasetStrId::Store), - graph_name: q.graph_name.map_id(DatasetStrId::Store), - }) - .map_err(|e| e.into()) - }) -} - -type QuadPattern = ( - Option>, - Option>, - Option>, - Option>, -); - -fn try_map_quad_pattern( - subject: Option>>, - predicate: Option>>, - object: Option>>, - graph_name: Option>>, -) -> Option> { - Some(( - transpose(subject.map(|t| t.try_map_id(unwrap_store_id).ok()))?, - transpose(predicate.map(|t| t.try_map_id(unwrap_store_id).ok()))?, - transpose(object.map(|t| t.try_map_id(unwrap_store_id).ok()))?, - transpose(graph_name.map(|t| t.try_map_id(unwrap_store_id).ok()))?, - )) -} - -fn transpose(o: Option>) -> Option> { - match o { - Some(Some(v)) => Some(Some(v)), - Some(None) => None, - None => Some(None), - } -} - -fn unwrap_store_id(id: DatasetStrId) -> Result { - match id { - DatasetStrId::Store(id) => Ok(id), - DatasetStrId::Temporary(_) => Err(()), - } -} - impl<'a, S: ReadableEncodedStore> StrContainer for &'a DatasetView { - fn insert_str(&mut self, value: &str) -> Result { - if let Some(id) = self.store.get_str_id(value).map_err(|e| e.into())? { - Ok(DatasetStrId::Store(id)) + fn insert_str(&mut self, value: &str) -> Result { + if let Some(hash) = self.store.get_str_id(value).map_err(|e| e.into())? { + Ok(hash) } else { let hash = StrHash::new(value); self.extra .borrow_mut() .entry(hash) .or_insert_with(|| value.to_owned()); - Ok(DatasetStrId::Temporary(hash)) + Ok(hash) } } } -#[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)] -pub enum DatasetStrId { - Store(I), - Temporary(StrHash), -} - -impl StrId for DatasetStrId {} - -struct EncodedDatasetSpec { - default: Option>>, - named: Option>>, +struct EncodedDatasetSpec { + default: Option>, + named: Option>, } diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index ec27237b..fa8497c4 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -29,7 +29,7 @@ use std::str; const REGEX_SIZE_LIMIT: usize = 1_000_000; -type EncodedTuplesIterator = Box, EvaluationError>>>; +type EncodedTuplesIterator = Box>>; pub(crate) struct SimpleEvaluator { dataset: Rc, @@ -51,7 +51,7 @@ impl Clone for SimpleEvaluator { impl + 'static> SimpleEvaluator where - for<'a> &'a S: StrContainer, + for<'a> &'a S: StrContainer, { pub fn new( dataset: Rc, @@ -68,7 +68,7 @@ where pub fn evaluate_select_plan( &self, - plan: &PlanNode, + plan: &PlanNode, variables: Rc>, ) -> Result { let iter = self.eval_plan(plan, EncodedTuple::with_capacity(variables.len())); @@ -77,10 +77,7 @@ where )) } - pub fn evaluate_ask_plan( - &self, - plan: &PlanNode, - ) -> Result { + pub fn evaluate_ask_plan(&self, plan: &PlanNode) -> Result { let from = EncodedTuple::with_capacity(plan.maybe_bound_variables().len()); match self.eval_plan(plan, from).next() { Some(Ok(_)) => Ok(QueryResults::Boolean(true)), @@ -91,8 +88,8 @@ where pub fn evaluate_construct_plan( &self, - plan: &PlanNode, - template: Vec>, + plan: &PlanNode, + template: Vec, ) -> Result { let from = EncodedTuple::with_capacity(plan.maybe_bound_variables().len()); Ok(QueryResults::Graph(QueryTripleIter { @@ -106,10 +103,7 @@ where })) } - pub fn evaluate_describe_plan( - &self, - plan: &PlanNode, - ) -> Result { + pub fn evaluate_describe_plan(&self, plan: &PlanNode) -> Result { let from = EncodedTuple::with_capacity(plan.maybe_bound_variables().len()); Ok(QueryResults::Graph(QueryTripleIter { iter: Box::new(DescribeIterator { @@ -120,11 +114,7 @@ where })) } - pub fn eval_plan( - &self, - node: &PlanNode, - from: EncodedTuple, - ) -> EncodedTuplesIterator { + pub fn eval_plan(&self, node: &PlanNode, from: EncodedTuple) -> EncodedTuplesIterator { match node { PlanNode::Init => Box::new(once(Ok(from))), PlanNode::StaticBindings { tuples } => Box::new(tuples.clone().into_iter().map(Ok)), @@ -208,7 +198,7 @@ where })) } } - let iter: EncodedTuplesIterator<_> = Box::new(iter.map(move |quad| { + let iter: EncodedTuplesIterator = Box::new(iter.map(move |quad| { let quad = quad?; let mut new_tuple = tuple.clone(); put_pattern_value(&subject, quad.subject, &mut new_tuple); @@ -239,7 +229,7 @@ where if let Some(graph_name) = get_pattern_value(&graph_name, &tuple) { graph_name } else { - let result: EncodedTuplesIterator<_> = + let result: EncodedTuplesIterator = Box::new(once(Err(EvaluationError::msg( "Unknown graph name is not allowed when evaluating property path", )))); @@ -443,10 +433,8 @@ where let key_mapping = key_mapping.clone(); let aggregates = aggregates.clone(); let mut errors = Vec::default(); - let mut accumulators_for_group = HashMap::< - Vec>>, - Vec>>, - >::default(); + let mut accumulators_for_group = + HashMap::>, Vec>>::default(); self.eval_plan(child, from) .filter_map(|result| match result { Ok(result) => Some(result), @@ -512,11 +500,11 @@ where fn evaluate_service( &self, - service_name: &PatternValue, + service_name: &PatternValue, graph_pattern: &GraphPattern, variables: Rc>, - from: &EncodedTuple, - ) -> Result, EvaluationError> { + from: &EncodedTuple, + ) -> Result { if let QueryResults::Solutions(iter) = self.service_handler.handle( self.dataset.decode_named_node( get_pattern_value(service_name, from) @@ -540,7 +528,7 @@ where &self, function: &PlanAggregationFunction, distinct: bool, - ) -> Box + 'static> { + ) -> Box { match function { PlanAggregationFunction::Count => { if distinct { @@ -581,10 +569,10 @@ where fn eval_path_from( &self, - path: &PlanPropertyPath, - start: EncodedTerm, - graph_name: EncodedTerm, - ) -> Box, EvaluationError>>> { + path: &PlanPropertyPath, + start: EncodedTerm, + graph_name: EncodedTerm, + ) -> Box>> { match path { PlanPropertyPath::Path(p) => Box::new( self.dataset @@ -644,10 +632,10 @@ where fn eval_path_to( &self, - path: &PlanPropertyPath, - end: EncodedTerm, - graph_name: EncodedTerm, - ) -> Box, EvaluationError>>> { + path: &PlanPropertyPath, + end: EncodedTerm, + graph_name: EncodedTerm, + ) -> Box>> { match path { PlanPropertyPath::Path(p) => Box::new( self.dataset @@ -707,13 +695,9 @@ where fn eval_open_path( &self, - path: &PlanPropertyPath, - graph_name: EncodedTerm, - ) -> Box< - dyn Iterator< - Item = Result<(EncodedTerm, EncodedTerm), EvaluationError>, - >, - > { + path: &PlanPropertyPath, + graph_name: EncodedTerm, + ) -> Box>> { match path { PlanPropertyPath::Path(p) => Box::new( self.dataset @@ -787,9 +771,8 @@ where fn get_subject_or_object_identity_pairs( &self, - graph_name: EncodedTerm, - ) -> impl Iterator, EncodedTerm), EvaluationError>> - { + graph_name: EncodedTerm, + ) -> impl Iterator> { self.dataset .encoded_quads_for_pattern(None, None, None, Some(graph_name)) .flat_map_ok(|t| once(Ok(t.subject)).chain(once(Ok(t.object)))) @@ -799,9 +782,9 @@ where #[allow(clippy::cast_possible_truncation, clippy::cast_precision_loss)] fn eval_expression( &self, - expression: &PlanExpression, - tuple: &EncodedTuple, - ) -> Option> { + expression: &PlanExpression, + tuple: &EncodedTuple, + ) -> Option { match expression { PlanExpression::Constant(t) => Some(*t), PlanExpression::Variable(v) => tuple.get(*v), @@ -1565,7 +1548,7 @@ where } } - fn to_bool(&self, term: EncodedTerm) -> Option { + fn to_bool(&self, term: EncodedTerm) -> Option { match term { EncodedTerm::BooleanLiteral(value) => Some(value), EncodedTerm::SmallStringLiteral(value) => Some(!value.is_empty()), @@ -1580,7 +1563,7 @@ where } } - fn to_string_id(&self, term: EncodedTerm) -> Option> { + fn to_string_id(&self, term: EncodedTerm) -> Option { match term { EncodedTerm::DefaultGraph => None, EncodedTerm::NamedNode { iri_id } => Some(iri_id.into()), @@ -1618,7 +1601,7 @@ where } } - fn to_simple_string(&self, term: EncodedTerm) -> Option { + fn to_simple_string(&self, term: EncodedTerm) -> Option { match term { EncodedTerm::SmallStringLiteral(value) => Some(value.into()), EncodedTerm::BigStringLiteral { value_id } => self.dataset.get_str(value_id).ok()?, @@ -1626,10 +1609,7 @@ where } } - fn to_simple_string_id( - &self, - term: EncodedTerm, - ) -> Option> { + fn to_simple_string_id(&self, term: EncodedTerm) -> Option { match term { EncodedTerm::SmallStringLiteral(value) => Some(value.into()), EncodedTerm::BigStringLiteral { value_id } => Some(value_id.into()), @@ -1637,7 +1617,7 @@ where } } - fn to_string(&self, term: EncodedTerm) -> Option { + fn to_string(&self, term: EncodedTerm) -> Option { match term { EncodedTerm::SmallStringLiteral(value) | EncodedTerm::SmallSmallLangStringLiteral { value, .. } @@ -1653,8 +1633,8 @@ where fn to_string_and_language( &self, - term: EncodedTerm, - ) -> Option<(String, Option>)> { + term: EncodedTerm, + ) -> Option<(String, Option)> { match term { EncodedTerm::SmallStringLiteral(value) => Some((value.into(), None)), EncodedTerm::BigStringLiteral { value_id } => { @@ -1680,17 +1660,17 @@ where } } - fn build_named_node(&self, iri: &str) -> Option> { + fn build_named_node(&self, iri: &str) -> Option { Some(EncodedTerm::NamedNode { iri_id: self.dataset.as_ref().encode_str(iri).ok()?, }) } - fn build_string_literal(&self, value: &str) -> Option> { + fn build_string_literal(&self, value: &str) -> Option { Some(self.build_string_literal_from_id(self.build_string_id(value)?)) } - fn build_string_literal_from_id(&self, id: SmallStringOrId) -> EncodedTerm { + fn build_string_literal_from_id(&self, id: SmallStringOrId) -> EncodedTerm { match id { SmallStringOrId::Small(value) => EncodedTerm::SmallStringLiteral(value), SmallStringOrId::Big(value_id) => EncodedTerm::BigStringLiteral { value_id }, @@ -1700,16 +1680,16 @@ where fn build_lang_string_literal( &self, value: &str, - language_id: SmallStringOrId, - ) -> Option> { + language_id: SmallStringOrId, + ) -> Option { Some(self.build_lang_string_literal_from_id(self.build_string_id(value)?, language_id)) } fn build_lang_string_literal_from_id( &self, - value_id: SmallStringOrId, - language_id: SmallStringOrId, - ) -> EncodedTerm { + value_id: SmallStringOrId, + language_id: SmallStringOrId, + ) -> EncodedTerm { match (value_id, language_id) { (SmallStringOrId::Small(value), SmallStringOrId::Small(language)) => { EncodedTerm::SmallSmallLangStringLiteral { value, language } @@ -1732,8 +1712,8 @@ where fn build_plain_literal( &self, value: &str, - language: Option>, - ) -> Option> { + language: Option, + ) -> Option { if let Some(language_id) = language { self.build_lang_string_literal(value, language_id) } else { @@ -1741,7 +1721,7 @@ where } } - fn build_string_id(&self, value: &str) -> Option> { + fn build_string_id(&self, value: &str) -> Option { Some(if let Ok(value) = SmallString::try_from(value) { value.into() } else { @@ -1749,7 +1729,7 @@ where }) } - fn build_language_id(&self, value: EncodedTerm) -> Option> { + fn build_language_id(&self, value: EncodedTerm) -> Option { let mut language = self.to_simple_string(value)?; language.make_ascii_lowercase(); self.build_string_id(LanguageTag::parse(language).ok()?.as_str()) @@ -1757,9 +1737,9 @@ where fn to_argument_compatible_strings( &self, - arg1: EncodedTerm, - arg2: EncodedTerm, - ) -> Option<(String, String, Option>)> { + arg1: EncodedTerm, + arg2: EncodedTerm, + ) -> Option<(String, String, Option)> { let (value1, language1) = self.to_string_and_language(arg1)?; let (value2, language2) = self.to_string_and_language(arg2)?; if language2.is_none() || language1 == language2 { @@ -1769,11 +1749,7 @@ where } } - fn compile_pattern( - &self, - pattern: EncodedTerm, - flags: Option>, - ) -> Option { + fn compile_pattern(&self, pattern: EncodedTerm, flags: Option) -> Option { // TODO Avoid to compile the regex each time let pattern = self.to_simple_string(pattern)?; let mut regex_builder = RegexBuilder::new(&pattern); @@ -1804,9 +1780,9 @@ where fn parse_numeric_operands( &self, - e1: &PlanExpression, - e2: &PlanExpression, - tuple: &EncodedTuple, + e1: &PlanExpression, + e2: &PlanExpression, + tuple: &EncodedTuple, ) -> Option { NumericBinaryOperands::new( self.eval_expression(e1, tuple)?, @@ -1816,7 +1792,7 @@ where fn decode_bindings( &self, - iter: EncodedTuplesIterator, + iter: EncodedTuplesIterator, variables: Rc>, ) -> QuerySolutionIter { let eval = self.clone(); @@ -1840,7 +1816,7 @@ where &self, variables: Rc>, iter: QuerySolutionIter, - ) -> EncodedTuplesIterator { + ) -> EncodedTuplesIterator { let eval = self.clone(); Box::new(iter.map(move |solution| { let mut encoder = eval.dataset.as_ref(); @@ -1862,7 +1838,7 @@ where clippy::cast_possible_truncation, clippy::cast_precision_loss )] - fn equals(&self, a: EncodedTerm, b: EncodedTerm) -> Option { + fn equals(&self, a: EncodedTerm, b: EncodedTerm) -> Option { match a { EncodedTerm::DefaultGraph | EncodedTerm::NamedNode { .. } @@ -2012,9 +1988,9 @@ where fn cmp_according_to_expression( &self, - tuple_a: &EncodedTuple, - tuple_b: &EncodedTuple, - expression: &PlanExpression, + tuple_a: &EncodedTuple, + tuple_b: &EncodedTuple, + expression: &PlanExpression, ) -> Ordering { self.cmp_terms( self.eval_expression(expression, tuple_a), @@ -2022,11 +1998,7 @@ where ) } - fn cmp_terms( - &self, - a: Option>, - b: Option>, - ) -> Ordering { + fn cmp_terms(&self, a: Option, b: Option) -> Ordering { match (a, b) { (Some(a), Some(b)) => match a { _ if a.is_blank_node() => match b { @@ -2052,11 +2024,7 @@ where } #[allow(clippy::cast_precision_loss)] - fn partial_cmp_literals( - &self, - a: EncodedTerm, - b: EncodedTerm, - ) -> Option { + fn partial_cmp_literals(&self, a: EncodedTerm, b: EncodedTerm) -> Option { match a { EncodedTerm::SmallStringLiteral(a) => match b { EncodedTerm::SmallStringLiteral(b) => a.partial_cmp(&b), @@ -2174,7 +2142,7 @@ where } } - fn compare_str_ids(&self, a: S::StrId, b: S::StrId) -> Option { + fn compare_str_ids(&self, a: StrHash, b: StrHash) -> Option { Some( self.dataset .get_str(a) @@ -2183,25 +2151,21 @@ where ) } - fn compare_str_id_str(&self, a: S::StrId, b: &str) -> Option { + fn compare_str_id_str(&self, a: StrHash, b: &str) -> Option { Some(self.dataset.get_str(a).ok()??.as_str().cmp(b)) } - fn compare_str_str_id(&self, a: &str, b: S::StrId) -> Option { + fn compare_str_str_id(&self, a: &str, b: StrHash) -> Option { Some(a.cmp(self.dataset.get_str(b).ok()??.as_str())) } - fn hash( - &self, - arg: &PlanExpression, - tuple: &EncodedTuple, - ) -> Option> { + fn hash(&self, arg: &PlanExpression, tuple: &EncodedTuple) -> Option { let input = self.to_simple_string(self.eval_expression(arg, tuple)?)?; let hash = hex::encode(H::new().chain(input.as_str()).finalize()); self.build_string_literal(&hash) } - fn datatype(&self, value: EncodedTerm) -> Option> { + fn datatype(&self, value: EncodedTerm) -> Option { //TODO: optimize? match value { EncodedTerm::NamedNode { .. } @@ -2269,7 +2233,7 @@ enum NumericBinaryOperands { impl NumericBinaryOperands { #[allow(clippy::cast_precision_loss)] - fn new(a: EncodedTerm, b: EncodedTerm) -> Option { + fn new(a: EncodedTerm, b: EncodedTerm) -> Option { match (a, b) { (EncodedTerm::FloatLiteral(v1), EncodedTerm::FloatLiteral(v2)) => { Some(NumericBinaryOperands::Float(v1, v2)) @@ -2387,32 +2351,25 @@ impl NumericBinaryOperands { } } -fn get_pattern_value( - selector: &PatternValue, - tuple: &EncodedTuple, -) -> Option> { +fn get_pattern_value(selector: &PatternValue, tuple: &EncodedTuple) -> Option { match selector { PatternValue::Constant(term) => Some(*term), PatternValue::Variable(v) => tuple.get(*v), } } -fn put_pattern_value( - selector: &PatternValue, - value: EncodedTerm, - tuple: &mut EncodedTuple, -) { +fn put_pattern_value(selector: &PatternValue, value: EncodedTerm, tuple: &mut EncodedTuple) { match selector { PatternValue::Constant(_) => (), PatternValue::Variable(v) => tuple.set(*v, value), } } -fn put_variable_value( +fn put_variable_value( selector: &Variable, variables: &[Variable], - value: EncodedTerm, - tuple: &mut EncodedTuple, + value: EncodedTerm, + tuple: &mut EncodedTuple, ) { for (i, v) in variables.iter().enumerate() { if selector == v { @@ -2422,17 +2379,13 @@ fn put_variable_value( } } -fn unbind_variables(binding: &mut EncodedTuple, variables: &[usize]) { +fn unbind_variables(binding: &mut EncodedTuple, variables: &[usize]) { for var in variables { binding.unset(*var) } } -fn combine_tuples( - mut a: EncodedTuple, - b: &EncodedTuple, - vars: &[usize], -) -> Option> { +fn combine_tuples(mut a: EncodedTuple, b: &EncodedTuple, vars: &[usize]) -> Option { for var in vars { if let Some(b_value) = b.get(*var) { if let Some(a_value) = a.get(*var) { @@ -2447,10 +2400,7 @@ fn combine_tuples( Some(a) } -pub fn are_compatible_and_not_disjointed( - a: &EncodedTuple, - b: &EncodedTuple, -) -> bool { +pub fn are_compatible_and_not_disjointed(a: &EncodedTuple, b: &EncodedTuple) -> bool { let mut found_intersection = false; for (a_value, b_value) in a.iter().zip(b.iter()) { if let (Some(a_value), Some(b_value)) = (a_value, b_value) { @@ -2463,16 +2413,16 @@ pub fn are_compatible_and_not_disjointed( found_intersection } -struct JoinIterator { - left: Vec>, - right_iter: EncodedTuplesIterator, - buffered_results: Vec, EvaluationError>>, +struct JoinIterator { + left: Vec, + right_iter: EncodedTuplesIterator, + buffered_results: Vec>, } -impl Iterator for JoinIterator { - type Item = Result, EvaluationError>; +impl Iterator for JoinIterator { + type Item = Result; - fn next(&mut self) -> Option, EvaluationError>> { + fn next(&mut self) -> Option> { loop { if let Some(result) = self.buffered_results.pop() { return Some(result); @@ -2490,15 +2440,15 @@ impl Iterator for JoinIterator { } } -struct AntiJoinIterator { - left_iter: EncodedTuplesIterator, - right: Vec>, +struct AntiJoinIterator { + left_iter: EncodedTuplesIterator, + right: Vec, } -impl Iterator for AntiJoinIterator { - type Item = Result, EvaluationError>; +impl Iterator for AntiJoinIterator { + type Item = Result; - fn next(&mut self) -> Option, EvaluationError>> { + fn next(&mut self) -> Option> { loop { match self.left_iter.next()? { Ok(left_tuple) => { @@ -2517,18 +2467,18 @@ impl Iterator for AntiJoinIterator { struct LeftJoinIterator { eval: SimpleEvaluator, - right_plan: Rc>, - left_iter: EncodedTuplesIterator, - current_right: EncodedTuplesIterator, + right_plan: Rc, + left_iter: EncodedTuplesIterator, + current_right: EncodedTuplesIterator, } impl + 'static> Iterator for LeftJoinIterator where - for<'a> &'a S: StrContainer, + for<'a> &'a S: StrContainer, { - type Item = Result, EvaluationError>; + type Item = Result; - fn next(&mut self) -> Option, EvaluationError>> { + fn next(&mut self) -> Option> { if let Some(tuple) = self.current_right.next() { return Some(tuple); } @@ -2548,20 +2498,20 @@ where struct BadLeftJoinIterator { eval: SimpleEvaluator, - right_plan: Rc>, - left_iter: EncodedTuplesIterator, - current_left: Option>, - current_right: EncodedTuplesIterator, + right_plan: Rc, + left_iter: EncodedTuplesIterator, + current_left: Option, + current_right: EncodedTuplesIterator, problem_vars: Rc>, } impl + 'static> Iterator for BadLeftJoinIterator where - for<'a> &'a S: StrContainer, + for<'a> &'a S: StrContainer, { - type Item = Result, EvaluationError>; + type Item = Result; - fn next(&mut self) -> Option, EvaluationError>> { + fn next(&mut self) -> Option> { while let Some(right_tuple) = self.current_right.next() { match right_tuple { Ok(right_tuple) => { @@ -2603,19 +2553,19 @@ where struct UnionIterator { eval: SimpleEvaluator, - plans: Vec>>, - input: EncodedTuple, - current_iterator: EncodedTuplesIterator, + plans: Vec>, + input: EncodedTuple, + current_iterator: EncodedTuplesIterator, current_plan: usize, } impl + 'static> Iterator for UnionIterator where - for<'a> &'a S: StrContainer, + for<'a> &'a S: StrContainer, { - type Item = Result, EvaluationError>; + type Item = Result; - fn next(&mut self) -> Option, EvaluationError>> { + fn next(&mut self) -> Option> { loop { if let Some(tuple) = self.current_iterator.next() { return Some(tuple); @@ -2633,10 +2583,10 @@ where struct ConstructIterator { eval: SimpleEvaluator, - iter: EncodedTuplesIterator, - template: Vec>, + iter: EncodedTuplesIterator, + template: Vec, buffered_results: Vec>, - bnodes: Vec>, + bnodes: Vec, } impl + 'static> Iterator for ConstructIterator { @@ -2672,11 +2622,11 @@ impl + 'static> Iterator for Co } } -fn get_triple_template_value( - selector: &TripleTemplateValue, - tuple: &EncodedTuple, - bnodes: &mut Vec>, -) -> Option> { +fn get_triple_template_value( + selector: &TripleTemplateValue, + tuple: &EncodedTuple, + bnodes: &mut Vec, +) -> Option { match selector { TripleTemplateValue::Constant(term) => Some(*term), TripleTemplateValue::Variable(v) => tuple.get(*v), @@ -2689,15 +2639,15 @@ fn get_triple_template_value( } } -fn new_bnode() -> EncodedTerm { +fn new_bnode() -> EncodedTerm { EncodedTerm::NumericalBlankNode { id: random() } } fn decode_triple( decoder: &D, - subject: EncodedTerm, - predicate: EncodedTerm, - object: EncodedTerm, + subject: EncodedTerm, + predicate: EncodedTerm, + object: EncodedTerm, ) -> Result { Ok(Triple::new( decoder.decode_named_or_blank_node(subject)?, @@ -2708,8 +2658,8 @@ fn decode_triple( struct DescribeIterator { eval: SimpleEvaluator, - iter: EncodedTuplesIterator, - quads: Box, EvaluationError>>>, + iter: EncodedTuplesIterator, + quads: Box>>, } impl + 'static> Iterator for DescribeIterator { @@ -2894,19 +2844,19 @@ impl< } } -trait Accumulator { - fn add(&mut self, element: Option>); +trait Accumulator { + fn add(&mut self, element: Option); - fn state(&self) -> Option>; + fn state(&self) -> Option; } #[derive(Default, Debug)] -struct DistinctAccumulator> { - seen: HashSet>>, +struct DistinctAccumulator { + seen: HashSet>, inner: T, } -impl> DistinctAccumulator { +impl DistinctAccumulator { fn new(inner: T) -> Self { Self { seen: HashSet::default(), @@ -2915,14 +2865,14 @@ impl> DistinctAccumulator { } } -impl> Accumulator for DistinctAccumulator { - fn add(&mut self, element: Option>) { +impl Accumulator for DistinctAccumulator { + fn add(&mut self, element: Option) { if self.seen.insert(element) { self.inner.add(element) } } - fn state(&self) -> Option> { + fn state(&self) -> Option { self.inner.state() } } @@ -2932,22 +2882,22 @@ struct CountAccumulator { count: i64, } -impl Accumulator for CountAccumulator { - fn add(&mut self, _element: Option>) { +impl Accumulator for CountAccumulator { + fn add(&mut self, _element: Option) { self.count += 1; } - fn state(&self) -> Option> { + fn state(&self) -> Option { Some(self.count.into()) } } #[derive(Debug)] -struct SumAccumulator { - sum: Option>, +struct SumAccumulator { + sum: Option, } -impl Default for SumAccumulator { +impl Default for SumAccumulator { fn default() -> Self { Self { sum: Some(0.into()), @@ -2955,8 +2905,8 @@ impl Default for SumAccumulator { } } -impl Accumulator for SumAccumulator { - fn add(&mut self, element: Option>) { +impl Accumulator for SumAccumulator { + fn add(&mut self, element: Option) { if let Some(sum) = self.sum { if let Some(operands) = element.and_then(|e| NumericBinaryOperands::new(sum, e)) { //TODO: unify with addition? @@ -2974,18 +2924,18 @@ impl Accumulator for SumAccumulator { } } - fn state(&self) -> Option> { + fn state(&self) -> Option { self.sum } } #[derive(Debug)] -struct AvgAccumulator { - sum: SumAccumulator, +struct AvgAccumulator { + sum: SumAccumulator, count: CountAccumulator, } -impl Default for AvgAccumulator { +impl Default for AvgAccumulator { fn default() -> Self { Self { sum: SumAccumulator::default(), @@ -2994,13 +2944,13 @@ impl Default for AvgAccumulator { } } -impl Accumulator for AvgAccumulator { - fn add(&mut self, element: Option>) { +impl Accumulator for AvgAccumulator { + fn add(&mut self, element: Option) { self.sum.add(element); self.count.add(element); } - fn state(&self) -> Option> { + fn state(&self) -> Option { let sum = self.sum.state()?; let count = self.count.state()?; if count == EncodedTerm::from(0) { @@ -3024,7 +2974,7 @@ impl Accumulator for AvgAccumulator { #[allow(clippy::option_option)] struct MinAccumulator { eval: SimpleEvaluator, - min: Option>>, + min: Option>, } impl MinAccumulator { @@ -3033,12 +2983,11 @@ impl MinAccumulator { } } -impl + 'static> Accumulator - for MinAccumulator +impl + 'static> Accumulator for MinAccumulator where - for<'a> &'a S: StrContainer, + for<'a> &'a S: StrContainer, { - fn add(&mut self, element: Option>) { + fn add(&mut self, element: Option) { if let Some(min) = self.min { if self.eval.cmp_terms(element, min) == Ordering::Less { self.min = Some(element) @@ -3048,7 +2997,7 @@ where } } - fn state(&self) -> Option> { + fn state(&self) -> Option { self.min.and_then(|v| v) } } @@ -3056,7 +3005,7 @@ where #[allow(clippy::option_option)] struct MaxAccumulator { eval: SimpleEvaluator, - max: Option>>, + max: Option>, } impl MaxAccumulator { @@ -3065,12 +3014,11 @@ impl MaxAccumulator { } } -impl + 'static> Accumulator - for MaxAccumulator +impl + 'static> Accumulator for MaxAccumulator where - for<'a> &'a S: StrContainer, + for<'a> &'a S: StrContainer, { - fn add(&mut self, element: Option>) { + fn add(&mut self, element: Option) { if let Some(max) = self.max { if self.eval.cmp_terms(element, max) == Ordering::Greater { self.max = Some(element) @@ -3080,30 +3028,30 @@ where } } - fn state(&self) -> Option> { + fn state(&self) -> Option { self.max.and_then(|v| v) } } #[derive(Debug)] -struct SampleAccumulator { - value: Option>, +struct SampleAccumulator { + value: Option, } -impl Default for SampleAccumulator { +impl Default for SampleAccumulator { fn default() -> Self { Self { value: None } } } -impl Accumulator for SampleAccumulator { - fn add(&mut self, element: Option>) { +impl Accumulator for SampleAccumulator { + fn add(&mut self, element: Option) { if element.is_some() { self.value = element } } - fn state(&self) -> Option> { + fn state(&self) -> Option { self.value } } @@ -3112,7 +3060,7 @@ impl Accumulator for SampleAccumulator { struct GroupConcatAccumulator { eval: SimpleEvaluator, concat: Option, - language: Option>>, + language: Option>, separator: Rc, } @@ -3127,12 +3075,12 @@ impl GroupConcatAccumulator { } } -impl + 'static> Accumulator +impl + 'static> Accumulator for GroupConcatAccumulator where - for<'a> &'a S: StrContainer, + for<'a> &'a S: StrContainer, { - fn add(&mut self, element: Option>) { + fn add(&mut self, element: Option) { if let Some(concat) = self.concat.as_mut() { if let Some(element) = element { if let Some((value, e_language)) = self.eval.to_string_and_language(element) { @@ -3150,7 +3098,7 @@ where } } - fn state(&self) -> Option> { + fn state(&self) -> Option { self.concat.as_ref().and_then(|result| { self.eval .build_plain_literal(result, self.language.and_then(|v| v)) @@ -3192,19 +3140,19 @@ fn write_hexa_bytes(bytes: &[u8], buffer: &mut String) { } #[derive(Eq, PartialEq, Clone, Copy)] -enum SmallStringOrId { +enum SmallStringOrId { Small(SmallString), - Big(I), + Big(StrHash), } -impl From for SmallStringOrId { +impl From for SmallStringOrId { fn from(value: SmallString) -> Self { Self::Small(value) } } -impl From for SmallStringOrId { - fn from(value: I) -> Self { +impl From for SmallStringOrId { + fn from(value: StrHash) -> Self { Self::Big(value) } } diff --git a/lib/src/sparql/mod.rs b/lib/src/sparql/mod.rs index 607df97a..34dd2211 100644 --- a/lib/src/sparql/mod.rs +++ b/lib/src/sparql/mod.rs @@ -182,7 +182,7 @@ impl From for UpdateOptions { pub(crate) fn evaluate_update< R: ReadableEncodedStore + Clone + 'static, - W: StrContainer + WritableEncodedStore, + W: StrContainer + WritableEncodedStore, >( read: R, write: &mut W, diff --git a/lib/src/sparql/plan.rs b/lib/src/sparql/plan.rs index 944fd6bd..10fbc369 100644 --- a/lib/src/sparql/plan.rs +++ b/lib/src/sparql/plan.rs @@ -1,89 +1,89 @@ use crate::sparql::algebra::GraphPattern; use crate::sparql::model::Variable; -use crate::store::numeric_encoder::{EncodedTerm, StrId}; +use crate::store::numeric_encoder::EncodedTerm; use std::collections::BTreeSet; use std::rc::Rc; #[derive(Eq, PartialEq, Debug, Clone, Hash)] -pub enum PlanNode { +pub enum PlanNode { Init, StaticBindings { - tuples: Vec>, + tuples: Vec, }, Service { - service_name: PatternValue, + service_name: PatternValue, variables: Rc>, - child: Rc>, + child: Rc, graph_pattern: Rc, silent: bool, }, QuadPatternJoin { - child: Rc>, - subject: PatternValue, - predicate: PatternValue, - object: PatternValue, - graph_name: PatternValue, + child: Rc, + subject: PatternValue, + predicate: PatternValue, + object: PatternValue, + graph_name: PatternValue, }, PathPatternJoin { - child: Rc>, - subject: PatternValue, - path: Rc>, - object: PatternValue, - graph_name: PatternValue, + child: Rc, + subject: PatternValue, + path: Rc, + object: PatternValue, + graph_name: PatternValue, }, Join { - left: Rc>, - right: Rc>, + left: Rc, + right: Rc, }, AntiJoin { - left: Rc>, - right: Rc>, + left: Rc, + right: Rc, }, Filter { - child: Rc>, - expression: Rc>, + child: Rc, + expression: Rc, }, Union { - children: Vec>>, + children: Vec>, }, LeftJoin { - left: Rc>, - right: Rc>, + left: Rc, + right: Rc, possible_problem_vars: Rc>, //Variables that should not be part of the entry of the left join }, Extend { - child: Rc>, + child: Rc, position: usize, - expression: Rc>, + expression: Rc, }, Sort { - child: Rc>, - by: Vec>, + child: Rc, + by: Vec, }, HashDeduplicate { - child: Rc>, + child: Rc, }, Skip { - child: Rc>, + child: Rc, count: usize, }, Limit { - child: Rc>, + child: Rc, count: usize, }, Project { - child: Rc>, + child: Rc, mapping: Rc>, // pairs of (variable key in child, variable key in output) }, Aggregate { // By definition the group by key are the range 0..key_mapping.len() - child: Rc>, + child: Rc, key_mapping: Rc>, // aggregate key pairs of (variable key in child, variable key in output) - aggregates: Rc, usize)>>, + aggregates: Rc>, }, } -impl PlanNode { +impl PlanNode { /// Returns variables that might be bound in the result set pub fn maybe_bound_variables(&self) -> BTreeSet { let mut set = BTreeSet::default(); @@ -194,12 +194,12 @@ impl PlanNode { } #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] -pub enum PatternValue { - Constant(EncodedTerm), +pub enum PatternValue { + Constant(EncodedTerm), Variable(usize), } -impl PatternValue { +impl PatternValue { pub fn is_var(&self) -> bool { match self { PatternValue::Constant(_) => false, @@ -209,107 +209,107 @@ impl PatternValue { } #[derive(Eq, PartialEq, Debug, Clone, Hash)] -pub enum PlanExpression { - Constant(EncodedTerm), +pub enum PlanExpression { + Constant(EncodedTerm), Variable(usize), - Exists(Rc>), - Or(Box>, Box>), - And(Box>, Box>), - Equal(Box>, Box>), - Greater(Box>, Box>), - GreaterOrEqual(Box>, Box>), - Less(Box>, Box>), - LessOrEqual(Box>, Box>), - In(Box>, Vec>), - Add(Box>, Box>), - Subtract(Box>, Box>), - Multiply(Box>, Box>), - Divide(Box>, Box>), - UnaryPlus(Box>), - UnaryMinus(Box>), - Not(Box>), - Str(Box>), - Lang(Box>), - LangMatches(Box>, Box>), - Datatype(Box>), + Exists(Rc), + Or(Box, Box), + And(Box, Box), + Equal(Box, Box), + Greater(Box, Box), + GreaterOrEqual(Box, Box), + Less(Box, Box), + LessOrEqual(Box, Box), + In(Box, Vec), + Add(Box, Box), + Subtract(Box, Box), + Multiply(Box, Box), + Divide(Box, Box), + UnaryPlus(Box), + UnaryMinus(Box), + Not(Box), + Str(Box), + Lang(Box), + LangMatches(Box, Box), + Datatype(Box), Bound(usize), - Iri(Box>), - BNode(Option>>), + Iri(Box), + BNode(Option>), Rand, - Abs(Box>), - Ceil(Box>), - Floor(Box>), - Round(Box>), - Concat(Vec>), + Abs(Box), + Ceil(Box), + Floor(Box), + Round(Box), + Concat(Vec), SubStr( - Box>, - Box>, - Option>>, + Box, + Box, + Option>, ), - StrLen(Box>), + StrLen(Box), Replace( - Box>, - Box>, - Box>, - Option>>, + Box, + Box, + Box, + Option>, ), - UCase(Box>), - LCase(Box>), - EncodeForUri(Box>), - Contains(Box>, Box>), - StrStarts(Box>, Box>), - StrEnds(Box>, Box>), - StrBefore(Box>, Box>), - StrAfter(Box>, Box>), - Year(Box>), - Month(Box>), - Day(Box>), - Hours(Box>), - Minutes(Box>), - Seconds(Box>), - Timezone(Box>), - Tz(Box>), + UCase(Box), + LCase(Box), + EncodeForUri(Box), + Contains(Box, Box), + StrStarts(Box, Box), + StrEnds(Box, Box), + StrBefore(Box, Box), + StrAfter(Box, Box), + Year(Box), + Month(Box), + Day(Box), + Hours(Box), + Minutes(Box), + Seconds(Box), + Timezone(Box), + Tz(Box), Now, Uuid, StrUuid, - Md5(Box>), - Sha1(Box>), - Sha256(Box>), - Sha384(Box>), - Sha512(Box>), - Coalesce(Vec>), + Md5(Box), + Sha1(Box), + Sha256(Box), + Sha384(Box), + Sha512(Box), + Coalesce(Vec), If( - Box>, - Box>, - Box>, + Box, + Box, + Box, ), - StrLang(Box>, Box>), - StrDt(Box>, Box>), - SameTerm(Box>, Box>), - IsIri(Box>), - IsBlank(Box>), - IsLiteral(Box>), - IsNumeric(Box>), + StrLang(Box, Box), + StrDt(Box, Box), + SameTerm(Box, Box), + IsIri(Box), + IsBlank(Box), + IsLiteral(Box), + IsNumeric(Box), Regex( - Box>, - Box>, - Option>>, + Box, + Box, + Option>, ), - BooleanCast(Box>), - DoubleCast(Box>), - FloatCast(Box>), - DecimalCast(Box>), - IntegerCast(Box>), - DateCast(Box>), - TimeCast(Box>), - DateTimeCast(Box>), - DurationCast(Box>), - YearMonthDurationCast(Box>), - DayTimeDurationCast(Box>), - StringCast(Box>), + BooleanCast(Box), + DoubleCast(Box), + FloatCast(Box), + DecimalCast(Box), + IntegerCast(Box), + DateCast(Box), + TimeCast(Box), + DateTimeCast(Box), + DurationCast(Box), + YearMonthDurationCast(Box), + DayTimeDurationCast(Box), + StringCast(Box), } -impl PlanExpression { +impl PlanExpression { pub fn add_maybe_bound_variables(&self, set: &mut BTreeSet) { match self { PlanExpression::Variable(v) | PlanExpression::Bound(v) => { @@ -425,9 +425,9 @@ impl PlanExpression { } #[derive(Eq, PartialEq, Debug, Clone, Hash)] -pub struct PlanAggregation { +pub struct PlanAggregation { pub function: PlanAggregationFunction, - pub parameter: Option>, + pub parameter: Option, pub distinct: bool, } @@ -443,43 +443,43 @@ pub enum PlanAggregationFunction { } #[derive(Eq, PartialEq, Debug, Clone, Hash)] -pub enum PlanPropertyPath { - Path(EncodedTerm), - Reverse(Rc>), - Sequence(Rc>, Rc>), - Alternative(Rc>, Rc>), - ZeroOrMore(Rc>), - OneOrMore(Rc>), - ZeroOrOne(Rc>), - NegatedPropertySet(Rc>>), +pub enum PlanPropertyPath { + Path(EncodedTerm), + Reverse(Rc), + Sequence(Rc, Rc), + Alternative(Rc, Rc), + ZeroOrMore(Rc), + OneOrMore(Rc), + ZeroOrOne(Rc), + NegatedPropertySet(Rc>), } #[derive(Eq, PartialEq, Debug, Clone, Hash)] -pub enum Comparator { - Asc(PlanExpression), - Desc(PlanExpression), +pub enum Comparator { + Asc(PlanExpression), + Desc(PlanExpression), } #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] -pub struct TripleTemplate { - pub subject: TripleTemplateValue, - pub predicate: TripleTemplateValue, - pub object: TripleTemplateValue, +pub struct TripleTemplate { + pub subject: TripleTemplateValue, + pub predicate: TripleTemplateValue, + pub object: TripleTemplateValue, } #[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)] -pub enum TripleTemplateValue { - Constant(EncodedTerm), +pub enum TripleTemplateValue { + Constant(EncodedTerm), BlankNode(usize), Variable(usize), } #[derive(Eq, PartialEq, Debug, Clone, Hash)] -pub struct EncodedTuple { - inner: Vec>>, +pub struct EncodedTuple { + inner: Vec>, } -impl EncodedTuple { +impl EncodedTuple { pub fn with_capacity(capacity: usize) -> Self { Self { inner: Vec::with_capacity(capacity), @@ -494,15 +494,15 @@ impl EncodedTuple { self.inner.get(index).map_or(false, Option::is_some) } - pub fn get(&self, index: usize) -> Option> { + pub fn get(&self, index: usize) -> Option { self.inner.get(index).cloned().unwrap_or(None) } - pub fn iter(&self) -> impl Iterator>> + '_ { + pub fn iter(&self) -> impl Iterator> + '_ { self.inner.iter().cloned() } - pub fn set(&mut self, index: usize, value: EncodedTerm) { + pub fn set(&mut self, index: usize, value: EncodedTerm) { if self.inner.len() <= index { self.inner.resize(index + 1, None); } @@ -515,7 +515,7 @@ impl EncodedTuple { } } - pub fn combine_with(&self, other: &EncodedTuple) -> Option { + pub fn combine_with(&self, other: &EncodedTuple) -> Option { if self.inner.len() < other.inner.len() { let mut result = other.inner.to_owned(); for (key, self_value) in self.inner.iter().enumerate() { @@ -550,9 +550,9 @@ impl EncodedTuple { } } -impl IntoIterator for EncodedTuple { - type Item = Option>; - type IntoIter = std::vec::IntoIter>>; +impl IntoIterator for EncodedTuple { + type Item = Option; + type IntoIter = std::vec::IntoIter>; fn into_iter(self) -> Self::IntoIter { self.inner.into_iter() diff --git a/lib/src/sparql/plan_builder.rs b/lib/src/sparql/plan_builder.rs index 754ef97d..d13891d0 100644 --- a/lib/src/sparql/plan_builder.rs +++ b/lib/src/sparql/plan_builder.rs @@ -15,7 +15,7 @@ impl> PlanBuilder { pub fn build( encoder: E, pattern: &GraphPattern, - ) -> Result<(PlanNode, Vec), EvaluationError> { + ) -> Result<(PlanNode, Vec), EvaluationError> { let mut variables = Vec::default(); let plan = PlanBuilder { encoder }.build_for_graph_pattern( pattern, @@ -29,7 +29,7 @@ impl> PlanBuilder { encoder: E, template: &[TriplePattern], mut variables: Vec, - ) -> Result>, EvaluationError> { + ) -> Result, EvaluationError> { PlanBuilder { encoder }.build_for_graph_template(template, &mut variables) } @@ -37,8 +37,8 @@ impl> PlanBuilder { &mut self, pattern: &GraphPattern, variables: &mut Vec, - graph_name: PatternValue, - ) -> Result, EvaluationError> { + graph_name: PatternValue, + ) -> Result { Ok(match pattern { GraphPattern::BGP(p) => self.build_for_bgp(p, variables, graph_name)?, GraphPattern::Path { @@ -268,8 +268,8 @@ impl> PlanBuilder { &mut self, p: &[TriplePattern], variables: &mut Vec, - graph_name: PatternValue, - ) -> Result, EvaluationError> { + graph_name: PatternValue, + ) -> Result { let mut plan = PlanNode::Init; for pattern in sort_bgp(p) { plan = PlanNode::QuadPatternJoin { @@ -287,7 +287,7 @@ impl> PlanBuilder { fn build_for_path( &mut self, path: &PropertyPathExpression, - ) -> Result, EvaluationError> { + ) -> Result { Ok(match path { PropertyPathExpression::NamedNode(p) => { PlanPropertyPath::Path(self.build_named_node(p)?) @@ -326,8 +326,8 @@ impl> PlanBuilder { &mut self, expression: &Expression, variables: &mut Vec, - graph_name: PatternValue, - ) -> Result, EvaluationError> { + graph_name: PatternValue, + ) -> Result { Ok(match expression { Expression::NamedNode(node) => PlanExpression::Constant(self.build_named_node(node)?), Expression::Literal(l) => PlanExpression::Constant(self.build_literal(l)?), @@ -728,11 +728,11 @@ impl> PlanBuilder { fn build_cast( &mut self, parameters: &[Expression], - constructor: impl Fn(Box>) -> PlanExpression, + constructor: impl Fn(Box) -> PlanExpression, variables: &mut Vec, - graph_name: PatternValue, + graph_name: PatternValue, name: &'static str, - ) -> Result, EvaluationError> { + ) -> Result { if parameters.len() == 1 { Ok(constructor(Box::new(self.build_for_expression( ¶meters[0], @@ -751,8 +751,8 @@ impl> PlanBuilder { &mut self, l: &[Expression], variables: &mut Vec, - graph_name: PatternValue, - ) -> Result>, EvaluationError> { + graph_name: PatternValue, + ) -> Result, EvaluationError> { l.iter() .map(|e| self.build_for_expression(e, variables, graph_name)) .collect() @@ -762,7 +762,7 @@ impl> PlanBuilder { &mut self, term_or_variable: &TermOrVariable, variables: &mut Vec, - ) -> Result, EvaluationError> { + ) -> Result { Ok(match term_or_variable { TermOrVariable::Variable(variable) => { PatternValue::Variable(variable_key(variables, variable)) @@ -782,7 +782,7 @@ impl> PlanBuilder { &mut self, named_node_or_variable: &NamedNodeOrVariable, variables: &mut Vec, - ) -> Result, EvaluationError> { + ) -> Result { Ok(match named_node_or_variable { NamedNodeOrVariable::NamedNode(named_node) => { PatternValue::Constant(self.build_named_node(named_node)?) @@ -798,7 +798,7 @@ impl> PlanBuilder { table_variables: &[Variable], rows: &[Vec>], variables: &mut Vec, - ) -> Result>, EvaluationError> { + ) -> Result, EvaluationError> { let bindings_variables_keys = table_variables .iter() .map(|v| variable_key(variables, v)) @@ -820,8 +820,8 @@ impl> PlanBuilder { &mut self, aggregate: &AggregationFunction, variables: &mut Vec, - graph_name: PatternValue, - ) -> Result, EvaluationError> { + graph_name: PatternValue, + ) -> Result { match aggregate { AggregationFunction::Count { expr, distinct } => Ok(PlanAggregation { function: PlanAggregationFunction::Count, @@ -877,7 +877,7 @@ impl> PlanBuilder { &mut self, template: &[TriplePattern], variables: &mut Vec, - ) -> Result>, EvaluationError> { + ) -> Result, EvaluationError> { let mut bnodes = Vec::default(); template .iter() @@ -905,7 +905,7 @@ impl> PlanBuilder { term_or_variable: &TermOrVariable, variables: &mut Vec, bnodes: &mut Vec, - ) -> Result, EvaluationError> { + ) -> Result { Ok(match term_or_variable { TermOrVariable::Variable(variable) => { TripleTemplateValue::Variable(variable_key(variables, variable)) @@ -921,7 +921,7 @@ impl> PlanBuilder { &mut self, named_node_or_variable: &NamedNodeOrVariable, variables: &mut Vec, - ) -> Result, EvaluationError> { + ) -> Result { Ok(match named_node_or_variable { NamedNodeOrVariable::Variable(variable) => { TripleTemplateValue::Variable(variable_key(variables, variable)) @@ -934,10 +934,10 @@ impl> PlanBuilder { fn convert_pattern_value_id( &self, - from_value: PatternValue, + from_value: PatternValue, from: &[Variable], to: &mut Vec, - ) -> PatternValue { + ) -> PatternValue { match from_value { PatternValue::Constant(v) => PatternValue::Constant(v), PatternValue::Variable(from_id) => { @@ -966,11 +966,7 @@ impl> PlanBuilder { } } - fn add_left_join_problematic_variables( - &self, - node: &PlanNode, - set: &mut BTreeSet, - ) { + fn add_left_join_problematic_variables(&self, node: &PlanNode, set: &mut BTreeSet) { match node { PlanNode::Init | PlanNode::StaticBindings { .. } @@ -1033,21 +1029,15 @@ impl> PlanBuilder { } } - fn build_named_node( - &mut self, - node: &NamedNode, - ) -> Result, EvaluationError> { + fn build_named_node(&mut self, node: &NamedNode) -> Result { self.encoder.encode_named_node(node.as_ref()) } - fn build_literal( - &mut self, - literal: &Literal, - ) -> Result, EvaluationError> { + fn build_literal(&mut self, literal: &Literal) -> Result { self.encoder.encode_literal(literal.as_ref()) } - fn build_term(&mut self, term: &Term) -> Result, EvaluationError> { + fn build_term(&mut self, term: &Term) -> Result { self.encoder.encode_term(term.as_ref()) } } diff --git a/lib/src/sparql/update.rs b/lib/src/sparql/update.rs index b1cd3b61..c7692dce 100644 --- a/lib/src/sparql/update.rs +++ b/lib/src/sparql/update.rs @@ -5,7 +5,7 @@ use crate::sparql::algebra::{ GraphPattern, GraphTarget, GraphUpdateOperation, NamedNodeOrVariable, QuadPattern, QueryDataset, TermOrVariable, }; -use crate::sparql::dataset::{DatasetStrId, DatasetView}; +use crate::sparql::dataset::DatasetView; use crate::sparql::eval::SimpleEvaluator; use crate::sparql::http::Client; use crate::sparql::plan::EncodedTuple; @@ -33,7 +33,7 @@ pub(crate) struct SimpleUpdateEvaluator<'a, R, W> { impl< 'a, R: ReadableEncodedStore + Clone + 'static, - W: StrContainer + WritableEncodedStore + 'a, + W: StrContainer + WritableEncodedStore + 'a, > SimpleUpdateEvaluator<'a, R, W> where io::Error: From>, @@ -127,28 +127,23 @@ where .into_iter() .map(|t| { Ok(if let Some(t) = t { - Some( - t.try_map_id(|id| { - if let DatasetStrId::Store(s) = id { - Ok(s) - } else { - self.write - .insert_str( - &dataset - .get_str(id) - .map_err(to_eval_error)? - .ok_or_else(|| { - EvaluationError::msg( - "String not stored in the string store", - ) - }) - .map_err(to_eval_error)?, - ) - .map_err(to_eval_error) - } - }) - .map_err(to_eval_error)?, - ) + t.on_each_id(|id| { + self.write + .insert_str( + &dataset + .get_str(id) + .map_err(to_eval_error)? + .ok_or_else(|| { + EvaluationError::msg( + "String not stored in the string store", + ) + }) + .map_err(to_eval_error)?, + ) + .map(|_| ()) + .map_err(to_eval_error) + })?; + Some(t) } else { None }) @@ -356,7 +351,7 @@ where &mut self, quad: &Quad, bnodes: &mut HashMap, - ) -> Result>, EvaluationError> { + ) -> Result, EvaluationError> { Ok(Some(EncodedQuad { subject: match &quad.subject { NamedOrBlankNode::NamedNode(subject) => { @@ -390,9 +385,9 @@ where &mut self, quad: &QuadPattern, variables: &[Variable], - values: &[Option>], + values: &[Option], bnodes: &mut HashMap, - ) -> Result>, EvaluationError> { + ) -> Result, EvaluationError> { Ok(Some(EncodedQuad { subject: if let Some(subject) = self.encode_term_for_insertion(&quad.subject, variables, values, bnodes, |t| { @@ -435,10 +430,10 @@ where &mut self, term: &TermOrVariable, variables: &[Variable], - values: &[Option>], + values: &[Option], bnodes: &mut HashMap, - validate: impl FnOnce(&EncodedTerm) -> bool, - ) -> Result>, EvaluationError> { + validate: impl FnOnce(&EncodedTerm) -> bool, + ) -> Result, EvaluationError> { Ok(match term { TermOrVariable::Term(term) => Some( self.write @@ -471,8 +466,8 @@ where &mut self, term: &NamedNodeOrVariable, variables: &[Variable], - values: &[Option>], - ) -> Result>, EvaluationError> { + values: &[Option], + ) -> Result, EvaluationError> { Ok(match term { NamedNodeOrVariable::NamedNode(term) => Some( self.write @@ -500,7 +495,7 @@ where fn encode_quad_for_deletion( &mut self, quad: &Quad, - ) -> Result>, EvaluationError> { + ) -> Result, EvaluationError> { Ok(Some(EncodedQuad { subject: if let Some(subject) = self .read @@ -545,8 +540,8 @@ where &self, quad: &QuadPattern, variables: &[Variable], - values: &[Option>], - ) -> Result>, EvaluationError> { + values: &[Option], + ) -> Result, EvaluationError> { Ok(Some(EncodedQuad { subject: if let Some(subject) = self.encode_term_for_deletion(&quad.subject, variables, values)? @@ -587,8 +582,8 @@ where &self, term: &TermOrVariable, variables: &[Variable], - values: &[Option>], - ) -> Result>, EvaluationError> { + values: &[Option], + ) -> Result, EvaluationError> { match term { TermOrVariable::Term(term) => { if term.is_blank_node() { @@ -619,8 +614,8 @@ where &self, term: &NamedNodeOrVariable, variables: &[Variable], - values: &[Option>], - ) -> Result>, EvaluationError> { + values: &[Option], + ) -> Result, EvaluationError> { Ok(match term { NamedNodeOrVariable::NamedNode(term) => self .read diff --git a/lib/src/store/binary_encoder.rs b/lib/src/store/binary_encoder.rs index 59863874..98933b28 100644 --- a/lib/src/store/binary_encoder.rs +++ b/lib/src/store/binary_encoder.rs @@ -6,8 +6,8 @@ use std::io; use std::io::{Cursor, Read}; use std::mem::size_of; -type EncodedTerm = crate::store::numeric_encoder::EncodedTerm; -type EncodedQuad = crate::store::numeric_encoder::EncodedQuad; +type EncodedTerm = crate::store::numeric_encoder::EncodedTerm; +type EncodedQuad = crate::store::numeric_encoder::EncodedQuad; pub const LATEST_STORAGE_VERSION: u64 = 1; pub const WRITTEN_TERM_MAX_SIZE: usize = size_of::() + 2 * size_of::(); @@ -648,7 +648,6 @@ mod tests { impl StrEncodingAware for MemoryStrStore { type Error = Infallible; - type StrId = StrHash; } impl StrLookup for MemoryStrStore { diff --git a/lib/src/store/mod.rs b/lib/src/store/mod.rs index d9df9089..6c879da2 100644 --- a/lib/src/store/mod.rs +++ b/lib/src/store/mod.rs @@ -24,44 +24,32 @@ use std::io::{BufRead, Write}; use std::iter::Iterator; pub(crate) trait ReadableEncodedStore: StrLookup { - type QuadsIter: Iterator, Self::Error>> + 'static; - type GraphsIter: Iterator, Self::Error>> + 'static; + type QuadsIter: Iterator> + 'static; + type GraphsIter: Iterator> + 'static; fn encoded_quads_for_pattern( &self, - subject: Option>, - predicate: Option>, - object: Option>, - graph_name: Option>, + subject: Option, + predicate: Option, + object: Option, + graph_name: Option, ) -> Self::QuadsIter; fn encoded_named_graphs(&self) -> Self::GraphsIter; - fn contains_encoded_named_graph( - &self, - graph_name: EncodedTerm, - ) -> Result; + fn contains_encoded_named_graph(&self, graph_name: EncodedTerm) -> Result; } pub(crate) trait WritableEncodedStore: StrEncodingAware { - fn insert_encoded(&mut self, quad: &EncodedQuad) -> Result<(), Self::Error>; + fn insert_encoded(&mut self, quad: &EncodedQuad) -> Result<(), Self::Error>; - fn remove_encoded(&mut self, quad: &EncodedQuad) -> Result<(), Self::Error>; + fn remove_encoded(&mut self, quad: &EncodedQuad) -> Result<(), Self::Error>; - fn insert_encoded_named_graph( - &mut self, - graph_name: EncodedTerm, - ) -> Result<(), Self::Error>; + fn insert_encoded_named_graph(&mut self, graph_name: EncodedTerm) -> Result<(), Self::Error>; - fn clear_encoded_graph( - &mut self, - graph_name: EncodedTerm, - ) -> Result<(), Self::Error>; + fn clear_encoded_graph(&mut self, graph_name: EncodedTerm) -> Result<(), Self::Error>; - fn remove_encoded_named_graph( - &mut self, - graph_name: EncodedTerm, - ) -> Result<(), Self::Error>; + fn remove_encoded_named_graph(&mut self, graph_name: EncodedTerm) -> Result<(), Self::Error>; fn clear(&mut self) -> Result<(), Self::Error>; } @@ -215,11 +203,11 @@ impl From> for io::Error { } } -type QuadPattern = ( - Option>, - Option>, - Option>, - Option>, +type QuadPattern = ( + Option, + Option, + Option, + Option, ); fn get_encoded_quad_pattern( @@ -228,7 +216,7 @@ fn get_encoded_quad_pattern( predicate: Option>, object: Option>, graph_name: Option>, -) -> Result>, E::Error> { +) -> Result, E::Error> { Ok(Some(( if let Some(subject) = transpose( subject diff --git a/lib/src/store/numeric_encoder.rs b/lib/src/store/numeric_encoder.rs index f7821203..73b6ca1d 100644 --- a/lib/src/store/numeric_encoder.rs +++ b/lib/src/store/numeric_encoder.rs @@ -16,8 +16,6 @@ use std::hash::Hash; use std::hash::Hasher; use std::{fmt, io, str}; -pub trait StrId: Eq + Debug + Copy + Hash {} - #[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)] #[repr(transparent)] pub struct StrHash { @@ -46,24 +44,22 @@ impl StrHash { } } -impl StrId for StrHash {} - #[derive(Debug, Clone, Copy)] -pub enum EncodedTerm { +pub enum EncodedTerm { DefaultGraph, NamedNode { - iri_id: I, + iri_id: StrHash, }, NumericalBlankNode { id: u128, }, SmallBlankNode(SmallString), BigBlankNode { - id_id: I, + id_id: StrHash, }, SmallStringLiteral(SmallString), BigStringLiteral { - value_id: I, + value_id: StrHash, }, SmallSmallLangStringLiteral { value: SmallString, @@ -71,23 +67,23 @@ pub enum EncodedTerm { }, SmallBigLangStringLiteral { value: SmallString, - language_id: I, + language_id: StrHash, }, BigSmallLangStringLiteral { - value_id: I, + value_id: StrHash, language: SmallString, }, BigBigLangStringLiteral { - value_id: I, - language_id: I, + value_id: StrHash, + language_id: StrHash, }, SmallTypedLiteral { value: SmallString, - datatype_id: I, + datatype_id: StrHash, }, BigTypedLiteral { - value_id: I, - datatype_id: I, + value_id: StrHash, + datatype_id: StrHash, }, BooleanLiteral(bool), FloatLiteral(f32), @@ -107,7 +103,7 @@ pub enum EncodedTerm { DayTimeDurationLiteral(DayTimeDuration), } -impl PartialEq for EncodedTerm { +impl PartialEq for EncodedTerm { fn eq(&self, other: &Self) -> bool { match (self, other) { (Self::DefaultGraph, Self::DefaultGraph) => true, @@ -223,9 +219,9 @@ impl PartialEq for EncodedTerm { } } -impl Eq for EncodedTerm {} +impl Eq for EncodedTerm {} -impl Hash for EncodedTerm { +impl Hash for EncodedTerm { fn hash(&self, state: &mut H) { match self { Self::NamedNode { iri_id } => iri_id.hash(state), @@ -285,7 +281,7 @@ impl Hash for EncodedTerm { } } -impl EncodedTerm { +impl EncodedTerm { pub fn is_named_node(&self) -> bool { matches!(self, Self::NamedNode { .. }) } @@ -340,241 +336,146 @@ impl EncodedTerm { matches!(self, Self::DefaultGraph) } - pub fn map_id(self, mapping: impl Fn(I) -> J) -> EncodedTerm { + pub fn on_each_id( + self, + mut callback: impl FnMut(StrHash) -> Result<(), E>, + ) -> Result<(), E> { match self { - Self::DefaultGraph { .. } => EncodedTerm::DefaultGraph, - Self::NamedNode { iri_id } => EncodedTerm::NamedNode { - iri_id: mapping(iri_id), - }, - Self::NumericalBlankNode { id } => EncodedTerm::NumericalBlankNode { id }, - Self::SmallBlankNode(id) => EncodedTerm::SmallBlankNode(id), - Self::BigBlankNode { id_id } => EncodedTerm::BigBlankNode { - id_id: mapping(id_id), - }, - Self::SmallStringLiteral(value) => EncodedTerm::SmallStringLiteral(value), - Self::BigStringLiteral { value_id } => EncodedTerm::BigStringLiteral { - value_id: mapping(value_id), - }, - Self::SmallSmallLangStringLiteral { value, language } => { - EncodedTerm::SmallSmallLangStringLiteral { value, language } + Self::NamedNode { iri_id } => { + callback(iri_id)?; } - Self::SmallBigLangStringLiteral { value, language_id } => { - EncodedTerm::SmallBigLangStringLiteral { - value, - language_id: mapping(language_id), - } + Self::BigBlankNode { id_id } => { + callback(id_id)?; } - Self::BigSmallLangStringLiteral { value_id, language } => { - EncodedTerm::BigSmallLangStringLiteral { - value_id: mapping(value_id), - language, - } + Self::BigStringLiteral { value_id } => { + callback(value_id)?; } - Self::BigBigLangStringLiteral { - value_id, - language_id, - } => EncodedTerm::BigBigLangStringLiteral { - value_id: mapping(value_id), - language_id: mapping(language_id), - }, - Self::SmallTypedLiteral { value, datatype_id } => EncodedTerm::SmallTypedLiteral { - value, - datatype_id: mapping(datatype_id), - }, - Self::BigTypedLiteral { - value_id, - datatype_id, - } => EncodedTerm::BigTypedLiteral { - value_id: mapping(value_id), - datatype_id: mapping(datatype_id), - }, - Self::BooleanLiteral(value) => EncodedTerm::BooleanLiteral(value), - Self::FloatLiteral(value) => EncodedTerm::FloatLiteral(value), - Self::DoubleLiteral(value) => EncodedTerm::DoubleLiteral(value), - Self::IntegerLiteral(value) => EncodedTerm::IntegerLiteral(value), - Self::DecimalLiteral(value) => EncodedTerm::DecimalLiteral(value), - Self::DateTimeLiteral(value) => EncodedTerm::DateTimeLiteral(value), - Self::DateLiteral(value) => EncodedTerm::DateLiteral(value), - Self::TimeLiteral(value) => EncodedTerm::TimeLiteral(value), - Self::GYearMonthLiteral(value) => EncodedTerm::GYearMonthLiteral(value), - Self::GYearLiteral(value) => EncodedTerm::GYearLiteral(value), - Self::GMonthDayLiteral(value) => EncodedTerm::GMonthDayLiteral(value), - Self::GDayLiteral(value) => EncodedTerm::GDayLiteral(value), - Self::GMonthLiteral(value) => EncodedTerm::GMonthLiteral(value), - Self::DurationLiteral(value) => EncodedTerm::DurationLiteral(value), - Self::YearMonthDurationLiteral(value) => EncodedTerm::YearMonthDurationLiteral(value), - Self::DayTimeDurationLiteral(value) => EncodedTerm::DayTimeDurationLiteral(value), - } - } - - pub fn try_map_id( - self, - mut mapping: impl FnMut(I) -> Result, - ) -> Result, E> { - Ok(match self { - Self::DefaultGraph { .. } => EncodedTerm::DefaultGraph, - Self::NamedNode { iri_id } => EncodedTerm::NamedNode { - iri_id: mapping(iri_id)?, - }, - Self::NumericalBlankNode { id } => EncodedTerm::NumericalBlankNode { id }, - Self::SmallBlankNode(id) => EncodedTerm::SmallBlankNode(id), - Self::BigBlankNode { id_id } => EncodedTerm::BigBlankNode { - id_id: mapping(id_id)?, - }, - Self::SmallStringLiteral(value) => EncodedTerm::SmallStringLiteral(value), - Self::BigStringLiteral { value_id } => EncodedTerm::BigStringLiteral { - value_id: mapping(value_id)?, - }, - Self::SmallSmallLangStringLiteral { value, language } => { - EncodedTerm::SmallSmallLangStringLiteral { value, language } + Self::SmallBigLangStringLiteral { language_id, .. } => { + callback(language_id)?; } - Self::SmallBigLangStringLiteral { value, language_id } => { - EncodedTerm::SmallBigLangStringLiteral { - value, - language_id: mapping(language_id)?, - } - } - Self::BigSmallLangStringLiteral { value_id, language } => { - EncodedTerm::BigSmallLangStringLiteral { - value_id: mapping(value_id)?, - language, - } + Self::BigSmallLangStringLiteral { value_id, .. } => { + callback(value_id)?; } Self::BigBigLangStringLiteral { value_id, language_id, - } => EncodedTerm::BigBigLangStringLiteral { - value_id: mapping(value_id)?, - language_id: mapping(language_id)?, - }, - Self::SmallTypedLiteral { value, datatype_id } => EncodedTerm::SmallTypedLiteral { - value, - datatype_id: mapping(datatype_id)?, - }, + } => { + callback(value_id)?; + callback(language_id)?; + } + Self::SmallTypedLiteral { datatype_id, .. } => { + callback(datatype_id)?; + } Self::BigTypedLiteral { value_id, datatype_id, - } => EncodedTerm::BigTypedLiteral { - value_id: mapping(value_id)?, - datatype_id: mapping(datatype_id)?, - }, - Self::BooleanLiteral(value) => EncodedTerm::BooleanLiteral(value), - Self::FloatLiteral(value) => EncodedTerm::FloatLiteral(value), - Self::DoubleLiteral(value) => EncodedTerm::DoubleLiteral(value), - Self::IntegerLiteral(value) => EncodedTerm::IntegerLiteral(value), - Self::DecimalLiteral(value) => EncodedTerm::DecimalLiteral(value), - Self::DateTimeLiteral(value) => EncodedTerm::DateTimeLiteral(value), - Self::DateLiteral(value) => EncodedTerm::DateLiteral(value), - Self::TimeLiteral(value) => EncodedTerm::TimeLiteral(value), - Self::GYearMonthLiteral(value) => EncodedTerm::GYearMonthLiteral(value), - Self::GYearLiteral(value) => EncodedTerm::GYearLiteral(value), - Self::GMonthDayLiteral(value) => EncodedTerm::GMonthDayLiteral(value), - Self::GDayLiteral(value) => EncodedTerm::GDayLiteral(value), - Self::GMonthLiteral(value) => EncodedTerm::GMonthLiteral(value), - Self::DurationLiteral(value) => EncodedTerm::DurationLiteral(value), - Self::YearMonthDurationLiteral(value) => EncodedTerm::YearMonthDurationLiteral(value), - Self::DayTimeDurationLiteral(value) => EncodedTerm::DayTimeDurationLiteral(value), - }) + } => { + callback(value_id)?; + callback(datatype_id)?; + } + _ => (), + } + Ok(()) } } -impl From for EncodedTerm { +impl From for EncodedTerm { fn from(value: bool) -> Self { Self::BooleanLiteral(value) } } -impl From for EncodedTerm { +impl From for EncodedTerm { fn from(value: i64) -> Self { Self::IntegerLiteral(value) } } -impl From for EncodedTerm { +impl From for EncodedTerm { fn from(value: i32) -> Self { Self::IntegerLiteral(value.into()) } } -impl From for EncodedTerm { +impl From for EncodedTerm { fn from(value: u32) -> Self { Self::IntegerLiteral(value.into()) } } -impl From for EncodedTerm { +impl From for EncodedTerm { fn from(value: u8) -> Self { Self::IntegerLiteral(value.into()) } } -impl From for EncodedTerm { +impl From for EncodedTerm { fn from(value: f32) -> Self { Self::FloatLiteral(value) } } -impl From for EncodedTerm { +impl From for EncodedTerm { fn from(value: f64) -> Self { Self::DoubleLiteral(value) } } -impl From for EncodedTerm { +impl From for EncodedTerm { fn from(value: Decimal) -> Self { Self::DecimalLiteral(value) } } -impl From for EncodedTerm { +impl From for EncodedTerm { fn from(value: DateTime) -> Self { Self::DateTimeLiteral(value) } } -impl From