|
|
@ -29,7 +29,7 @@ use std::str; |
|
|
|
|
|
|
|
|
|
|
|
const REGEX_SIZE_LIMIT: usize = 1_000_000; |
|
|
|
const REGEX_SIZE_LIMIT: usize = 1_000_000; |
|
|
|
|
|
|
|
|
|
|
|
type EncodedTuplesIterator<I> = Box<dyn Iterator<Item = Result<EncodedTuple<I>, EvaluationError>>>; |
|
|
|
type EncodedTuplesIterator = Box<dyn Iterator<Item = Result<EncodedTuple, EvaluationError>>>; |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) struct SimpleEvaluator<S> { |
|
|
|
pub(crate) struct SimpleEvaluator<S> { |
|
|
|
dataset: Rc<S>, |
|
|
|
dataset: Rc<S>, |
|
|
@ -51,7 +51,7 @@ impl<S> Clone for SimpleEvaluator<S> { |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> SimpleEvaluator<S> |
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> SimpleEvaluator<S> |
|
|
|
where |
|
|
|
where |
|
|
|
for<'a> &'a S: StrContainer<StrId = S::StrId>, |
|
|
|
for<'a> &'a S: StrContainer, |
|
|
|
{ |
|
|
|
{ |
|
|
|
pub fn new( |
|
|
|
pub fn new( |
|
|
|
dataset: Rc<S>, |
|
|
|
dataset: Rc<S>, |
|
|
@ -68,7 +68,7 @@ where |
|
|
|
|
|
|
|
|
|
|
|
pub fn evaluate_select_plan( |
|
|
|
pub fn evaluate_select_plan( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
plan: &PlanNode<S::StrId>, |
|
|
|
plan: &PlanNode, |
|
|
|
variables: Rc<Vec<Variable>>, |
|
|
|
variables: Rc<Vec<Variable>>, |
|
|
|
) -> Result<QueryResults, EvaluationError> { |
|
|
|
) -> Result<QueryResults, EvaluationError> { |
|
|
|
let iter = self.eval_plan(plan, EncodedTuple::with_capacity(variables.len())); |
|
|
|
let iter = self.eval_plan(plan, EncodedTuple::with_capacity(variables.len())); |
|
|
@ -77,10 +77,7 @@ where |
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn evaluate_ask_plan( |
|
|
|
pub fn evaluate_ask_plan(&self, plan: &PlanNode) -> Result<QueryResults, EvaluationError> { |
|
|
|
&self, |
|
|
|
|
|
|
|
plan: &PlanNode<S::StrId>, |
|
|
|
|
|
|
|
) -> Result<QueryResults, EvaluationError> { |
|
|
|
|
|
|
|
let from = EncodedTuple::with_capacity(plan.maybe_bound_variables().len()); |
|
|
|
let from = EncodedTuple::with_capacity(plan.maybe_bound_variables().len()); |
|
|
|
match self.eval_plan(plan, from).next() { |
|
|
|
match self.eval_plan(plan, from).next() { |
|
|
|
Some(Ok(_)) => Ok(QueryResults::Boolean(true)), |
|
|
|
Some(Ok(_)) => Ok(QueryResults::Boolean(true)), |
|
|
@ -91,8 +88,8 @@ where |
|
|
|
|
|
|
|
|
|
|
|
pub fn evaluate_construct_plan( |
|
|
|
pub fn evaluate_construct_plan( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
plan: &PlanNode<S::StrId>, |
|
|
|
plan: &PlanNode, |
|
|
|
template: Vec<TripleTemplate<S::StrId>>, |
|
|
|
template: Vec<TripleTemplate>, |
|
|
|
) -> Result<QueryResults, EvaluationError> { |
|
|
|
) -> Result<QueryResults, EvaluationError> { |
|
|
|
let from = EncodedTuple::with_capacity(plan.maybe_bound_variables().len()); |
|
|
|
let from = EncodedTuple::with_capacity(plan.maybe_bound_variables().len()); |
|
|
|
Ok(QueryResults::Graph(QueryTripleIter { |
|
|
|
Ok(QueryResults::Graph(QueryTripleIter { |
|
|
@ -106,10 +103,7 @@ where |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn evaluate_describe_plan( |
|
|
|
pub fn evaluate_describe_plan(&self, plan: &PlanNode) -> Result<QueryResults, EvaluationError> { |
|
|
|
&self, |
|
|
|
|
|
|
|
plan: &PlanNode<S::StrId>, |
|
|
|
|
|
|
|
) -> Result<QueryResults, EvaluationError> { |
|
|
|
|
|
|
|
let from = EncodedTuple::with_capacity(plan.maybe_bound_variables().len()); |
|
|
|
let from = EncodedTuple::with_capacity(plan.maybe_bound_variables().len()); |
|
|
|
Ok(QueryResults::Graph(QueryTripleIter { |
|
|
|
Ok(QueryResults::Graph(QueryTripleIter { |
|
|
|
iter: Box::new(DescribeIterator { |
|
|
|
iter: Box::new(DescribeIterator { |
|
|
@ -120,11 +114,7 @@ where |
|
|
|
})) |
|
|
|
})) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn eval_plan( |
|
|
|
pub fn eval_plan(&self, node: &PlanNode, from: EncodedTuple) -> EncodedTuplesIterator { |
|
|
|
&self, |
|
|
|
|
|
|
|
node: &PlanNode<S::StrId>, |
|
|
|
|
|
|
|
from: EncodedTuple<S::StrId>, |
|
|
|
|
|
|
|
) -> EncodedTuplesIterator<S::StrId> { |
|
|
|
|
|
|
|
match node { |
|
|
|
match node { |
|
|
|
PlanNode::Init => Box::new(once(Ok(from))), |
|
|
|
PlanNode::Init => Box::new(once(Ok(from))), |
|
|
|
PlanNode::StaticBindings { tuples } => Box::new(tuples.clone().into_iter().map(Ok)), |
|
|
|
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 quad = quad?; |
|
|
|
let mut new_tuple = tuple.clone(); |
|
|
|
let mut new_tuple = tuple.clone(); |
|
|
|
put_pattern_value(&subject, quad.subject, &mut new_tuple); |
|
|
|
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) { |
|
|
|
if let Some(graph_name) = get_pattern_value(&graph_name, &tuple) { |
|
|
|
graph_name |
|
|
|
graph_name |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
let result: EncodedTuplesIterator<_> = |
|
|
|
let result: EncodedTuplesIterator = |
|
|
|
Box::new(once(Err(EvaluationError::msg( |
|
|
|
Box::new(once(Err(EvaluationError::msg( |
|
|
|
"Unknown graph name is not allowed when evaluating property path", |
|
|
|
"Unknown graph name is not allowed when evaluating property path", |
|
|
|
)))); |
|
|
|
)))); |
|
|
@ -443,10 +433,8 @@ where |
|
|
|
let key_mapping = key_mapping.clone(); |
|
|
|
let key_mapping = key_mapping.clone(); |
|
|
|
let aggregates = aggregates.clone(); |
|
|
|
let aggregates = aggregates.clone(); |
|
|
|
let mut errors = Vec::default(); |
|
|
|
let mut errors = Vec::default(); |
|
|
|
let mut accumulators_for_group = HashMap::< |
|
|
|
let mut accumulators_for_group = |
|
|
|
Vec<Option<EncodedTerm<S::StrId>>>, |
|
|
|
HashMap::<Vec<Option<EncodedTerm>>, Vec<Box<dyn Accumulator>>>::default(); |
|
|
|
Vec<Box<dyn Accumulator<S::StrId>>>, |
|
|
|
|
|
|
|
>::default(); |
|
|
|
|
|
|
|
self.eval_plan(child, from) |
|
|
|
self.eval_plan(child, from) |
|
|
|
.filter_map(|result| match result { |
|
|
|
.filter_map(|result| match result { |
|
|
|
Ok(result) => Some(result), |
|
|
|
Ok(result) => Some(result), |
|
|
@ -512,11 +500,11 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn evaluate_service( |
|
|
|
fn evaluate_service( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
service_name: &PatternValue<S::StrId>, |
|
|
|
service_name: &PatternValue, |
|
|
|
graph_pattern: &GraphPattern, |
|
|
|
graph_pattern: &GraphPattern, |
|
|
|
variables: Rc<Vec<Variable>>, |
|
|
|
variables: Rc<Vec<Variable>>, |
|
|
|
from: &EncodedTuple<S::StrId>, |
|
|
|
from: &EncodedTuple, |
|
|
|
) -> Result<EncodedTuplesIterator<S::StrId>, EvaluationError> { |
|
|
|
) -> Result<EncodedTuplesIterator, EvaluationError> { |
|
|
|
if let QueryResults::Solutions(iter) = self.service_handler.handle( |
|
|
|
if let QueryResults::Solutions(iter) = self.service_handler.handle( |
|
|
|
self.dataset.decode_named_node( |
|
|
|
self.dataset.decode_named_node( |
|
|
|
get_pattern_value(service_name, from) |
|
|
|
get_pattern_value(service_name, from) |
|
|
@ -540,7 +528,7 @@ where |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
function: &PlanAggregationFunction, |
|
|
|
function: &PlanAggregationFunction, |
|
|
|
distinct: bool, |
|
|
|
distinct: bool, |
|
|
|
) -> Box<dyn Accumulator<S::StrId> + 'static> { |
|
|
|
) -> Box<dyn Accumulator + 'static> { |
|
|
|
match function { |
|
|
|
match function { |
|
|
|
PlanAggregationFunction::Count => { |
|
|
|
PlanAggregationFunction::Count => { |
|
|
|
if distinct { |
|
|
|
if distinct { |
|
|
@ -581,10 +569,10 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn eval_path_from( |
|
|
|
fn eval_path_from( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
path: &PlanPropertyPath<S::StrId>, |
|
|
|
path: &PlanPropertyPath, |
|
|
|
start: EncodedTerm<S::StrId>, |
|
|
|
start: EncodedTerm, |
|
|
|
graph_name: EncodedTerm<S::StrId>, |
|
|
|
graph_name: EncodedTerm, |
|
|
|
) -> Box<dyn Iterator<Item = Result<EncodedTerm<S::StrId>, EvaluationError>>> { |
|
|
|
) -> Box<dyn Iterator<Item = Result<EncodedTerm, EvaluationError>>> { |
|
|
|
match path { |
|
|
|
match path { |
|
|
|
PlanPropertyPath::Path(p) => Box::new( |
|
|
|
PlanPropertyPath::Path(p) => Box::new( |
|
|
|
self.dataset |
|
|
|
self.dataset |
|
|
@ -644,10 +632,10 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn eval_path_to( |
|
|
|
fn eval_path_to( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
path: &PlanPropertyPath<S::StrId>, |
|
|
|
path: &PlanPropertyPath, |
|
|
|
end: EncodedTerm<S::StrId>, |
|
|
|
end: EncodedTerm, |
|
|
|
graph_name: EncodedTerm<S::StrId>, |
|
|
|
graph_name: EncodedTerm, |
|
|
|
) -> Box<dyn Iterator<Item = Result<EncodedTerm<S::StrId>, EvaluationError>>> { |
|
|
|
) -> Box<dyn Iterator<Item = Result<EncodedTerm, EvaluationError>>> { |
|
|
|
match path { |
|
|
|
match path { |
|
|
|
PlanPropertyPath::Path(p) => Box::new( |
|
|
|
PlanPropertyPath::Path(p) => Box::new( |
|
|
|
self.dataset |
|
|
|
self.dataset |
|
|
@ -707,13 +695,9 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn eval_open_path( |
|
|
|
fn eval_open_path( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
path: &PlanPropertyPath<S::StrId>, |
|
|
|
path: &PlanPropertyPath, |
|
|
|
graph_name: EncodedTerm<S::StrId>, |
|
|
|
graph_name: EncodedTerm, |
|
|
|
) -> Box< |
|
|
|
) -> Box<dyn Iterator<Item = Result<(EncodedTerm, EncodedTerm), EvaluationError>>> { |
|
|
|
dyn Iterator< |
|
|
|
|
|
|
|
Item = Result<(EncodedTerm<S::StrId>, EncodedTerm<S::StrId>), EvaluationError>, |
|
|
|
|
|
|
|
>, |
|
|
|
|
|
|
|
> { |
|
|
|
|
|
|
|
match path { |
|
|
|
match path { |
|
|
|
PlanPropertyPath::Path(p) => Box::new( |
|
|
|
PlanPropertyPath::Path(p) => Box::new( |
|
|
|
self.dataset |
|
|
|
self.dataset |
|
|
@ -787,9 +771,8 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn get_subject_or_object_identity_pairs( |
|
|
|
fn get_subject_or_object_identity_pairs( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
graph_name: EncodedTerm<S::StrId>, |
|
|
|
graph_name: EncodedTerm, |
|
|
|
) -> impl Iterator<Item = Result<(EncodedTerm<S::StrId>, EncodedTerm<S::StrId>), EvaluationError>> |
|
|
|
) -> impl Iterator<Item = Result<(EncodedTerm, EncodedTerm), EvaluationError>> { |
|
|
|
{ |
|
|
|
|
|
|
|
self.dataset |
|
|
|
self.dataset |
|
|
|
.encoded_quads_for_pattern(None, None, None, Some(graph_name)) |
|
|
|
.encoded_quads_for_pattern(None, None, None, Some(graph_name)) |
|
|
|
.flat_map_ok(|t| once(Ok(t.subject)).chain(once(Ok(t.object)))) |
|
|
|
.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)] |
|
|
|
#[allow(clippy::cast_possible_truncation, clippy::cast_precision_loss)] |
|
|
|
fn eval_expression( |
|
|
|
fn eval_expression( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
expression: &PlanExpression<S::StrId>, |
|
|
|
expression: &PlanExpression, |
|
|
|
tuple: &EncodedTuple<S::StrId>, |
|
|
|
tuple: &EncodedTuple, |
|
|
|
) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
) -> Option<EncodedTerm> { |
|
|
|
match expression { |
|
|
|
match expression { |
|
|
|
PlanExpression::Constant(t) => Some(*t), |
|
|
|
PlanExpression::Constant(t) => Some(*t), |
|
|
|
PlanExpression::Variable(v) => tuple.get(*v), |
|
|
|
PlanExpression::Variable(v) => tuple.get(*v), |
|
|
@ -1565,7 +1548,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn to_bool(&self, term: EncodedTerm<S::StrId>) -> Option<bool> { |
|
|
|
fn to_bool(&self, term: EncodedTerm) -> Option<bool> { |
|
|
|
match term { |
|
|
|
match term { |
|
|
|
EncodedTerm::BooleanLiteral(value) => Some(value), |
|
|
|
EncodedTerm::BooleanLiteral(value) => Some(value), |
|
|
|
EncodedTerm::SmallStringLiteral(value) => Some(!value.is_empty()), |
|
|
|
EncodedTerm::SmallStringLiteral(value) => Some(!value.is_empty()), |
|
|
@ -1580,7 +1563,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn to_string_id(&self, term: EncodedTerm<S::StrId>) -> Option<SmallStringOrId<S::StrId>> { |
|
|
|
fn to_string_id(&self, term: EncodedTerm) -> Option<SmallStringOrId> { |
|
|
|
match term { |
|
|
|
match term { |
|
|
|
EncodedTerm::DefaultGraph => None, |
|
|
|
EncodedTerm::DefaultGraph => None, |
|
|
|
EncodedTerm::NamedNode { iri_id } => Some(iri_id.into()), |
|
|
|
EncodedTerm::NamedNode { iri_id } => Some(iri_id.into()), |
|
|
@ -1618,7 +1601,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn to_simple_string(&self, term: EncodedTerm<S::StrId>) -> Option<String> { |
|
|
|
fn to_simple_string(&self, term: EncodedTerm) -> Option<String> { |
|
|
|
match term { |
|
|
|
match term { |
|
|
|
EncodedTerm::SmallStringLiteral(value) => Some(value.into()), |
|
|
|
EncodedTerm::SmallStringLiteral(value) => Some(value.into()), |
|
|
|
EncodedTerm::BigStringLiteral { value_id } => self.dataset.get_str(value_id).ok()?, |
|
|
|
EncodedTerm::BigStringLiteral { value_id } => self.dataset.get_str(value_id).ok()?, |
|
|
@ -1626,10 +1609,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn to_simple_string_id( |
|
|
|
fn to_simple_string_id(&self, term: EncodedTerm) -> Option<SmallStringOrId> { |
|
|
|
&self, |
|
|
|
|
|
|
|
term: EncodedTerm<S::StrId>, |
|
|
|
|
|
|
|
) -> Option<SmallStringOrId<S::StrId>> { |
|
|
|
|
|
|
|
match term { |
|
|
|
match term { |
|
|
|
EncodedTerm::SmallStringLiteral(value) => Some(value.into()), |
|
|
|
EncodedTerm::SmallStringLiteral(value) => Some(value.into()), |
|
|
|
EncodedTerm::BigStringLiteral { value_id } => Some(value_id.into()), |
|
|
|
EncodedTerm::BigStringLiteral { value_id } => Some(value_id.into()), |
|
|
@ -1637,7 +1617,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn to_string(&self, term: EncodedTerm<S::StrId>) -> Option<String> { |
|
|
|
fn to_string(&self, term: EncodedTerm) -> Option<String> { |
|
|
|
match term { |
|
|
|
match term { |
|
|
|
EncodedTerm::SmallStringLiteral(value) |
|
|
|
EncodedTerm::SmallStringLiteral(value) |
|
|
|
| EncodedTerm::SmallSmallLangStringLiteral { value, .. } |
|
|
|
| EncodedTerm::SmallSmallLangStringLiteral { value, .. } |
|
|
@ -1653,8 +1633,8 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn to_string_and_language( |
|
|
|
fn to_string_and_language( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
term: EncodedTerm<S::StrId>, |
|
|
|
term: EncodedTerm, |
|
|
|
) -> Option<(String, Option<SmallStringOrId<S::StrId>>)> { |
|
|
|
) -> Option<(String, Option<SmallStringOrId>)> { |
|
|
|
match term { |
|
|
|
match term { |
|
|
|
EncodedTerm::SmallStringLiteral(value) => Some((value.into(), None)), |
|
|
|
EncodedTerm::SmallStringLiteral(value) => Some((value.into(), None)), |
|
|
|
EncodedTerm::BigStringLiteral { value_id } => { |
|
|
|
EncodedTerm::BigStringLiteral { value_id } => { |
|
|
@ -1680,17 +1660,17 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn build_named_node(&self, iri: &str) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
fn build_named_node(&self, iri: &str) -> Option<EncodedTerm> { |
|
|
|
Some(EncodedTerm::NamedNode { |
|
|
|
Some(EncodedTerm::NamedNode { |
|
|
|
iri_id: self.dataset.as_ref().encode_str(iri).ok()?, |
|
|
|
iri_id: self.dataset.as_ref().encode_str(iri).ok()?, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn build_string_literal(&self, value: &str) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
fn build_string_literal(&self, value: &str) -> Option<EncodedTerm> { |
|
|
|
Some(self.build_string_literal_from_id(self.build_string_id(value)?)) |
|
|
|
Some(self.build_string_literal_from_id(self.build_string_id(value)?)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn build_string_literal_from_id(&self, id: SmallStringOrId<S::StrId>) -> EncodedTerm<S::StrId> { |
|
|
|
fn build_string_literal_from_id(&self, id: SmallStringOrId) -> EncodedTerm { |
|
|
|
match id { |
|
|
|
match id { |
|
|
|
SmallStringOrId::Small(value) => EncodedTerm::SmallStringLiteral(value), |
|
|
|
SmallStringOrId::Small(value) => EncodedTerm::SmallStringLiteral(value), |
|
|
|
SmallStringOrId::Big(value_id) => EncodedTerm::BigStringLiteral { value_id }, |
|
|
|
SmallStringOrId::Big(value_id) => EncodedTerm::BigStringLiteral { value_id }, |
|
|
@ -1700,16 +1680,16 @@ where |
|
|
|
fn build_lang_string_literal( |
|
|
|
fn build_lang_string_literal( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
value: &str, |
|
|
|
value: &str, |
|
|
|
language_id: SmallStringOrId<S::StrId>, |
|
|
|
language_id: SmallStringOrId, |
|
|
|
) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
) -> Option<EncodedTerm> { |
|
|
|
Some(self.build_lang_string_literal_from_id(self.build_string_id(value)?, language_id)) |
|
|
|
Some(self.build_lang_string_literal_from_id(self.build_string_id(value)?, language_id)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn build_lang_string_literal_from_id( |
|
|
|
fn build_lang_string_literal_from_id( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
value_id: SmallStringOrId<S::StrId>, |
|
|
|
value_id: SmallStringOrId, |
|
|
|
language_id: SmallStringOrId<S::StrId>, |
|
|
|
language_id: SmallStringOrId, |
|
|
|
) -> EncodedTerm<S::StrId> { |
|
|
|
) -> EncodedTerm { |
|
|
|
match (value_id, language_id) { |
|
|
|
match (value_id, language_id) { |
|
|
|
(SmallStringOrId::Small(value), SmallStringOrId::Small(language)) => { |
|
|
|
(SmallStringOrId::Small(value), SmallStringOrId::Small(language)) => { |
|
|
|
EncodedTerm::SmallSmallLangStringLiteral { value, language } |
|
|
|
EncodedTerm::SmallSmallLangStringLiteral { value, language } |
|
|
@ -1732,8 +1712,8 @@ where |
|
|
|
fn build_plain_literal( |
|
|
|
fn build_plain_literal( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
value: &str, |
|
|
|
value: &str, |
|
|
|
language: Option<SmallStringOrId<S::StrId>>, |
|
|
|
language: Option<SmallStringOrId>, |
|
|
|
) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
) -> Option<EncodedTerm> { |
|
|
|
if let Some(language_id) = language { |
|
|
|
if let Some(language_id) = language { |
|
|
|
self.build_lang_string_literal(value, language_id) |
|
|
|
self.build_lang_string_literal(value, language_id) |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -1741,7 +1721,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn build_string_id(&self, value: &str) -> Option<SmallStringOrId<S::StrId>> { |
|
|
|
fn build_string_id(&self, value: &str) -> Option<SmallStringOrId> { |
|
|
|
Some(if let Ok(value) = SmallString::try_from(value) { |
|
|
|
Some(if let Ok(value) = SmallString::try_from(value) { |
|
|
|
value.into() |
|
|
|
value.into() |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -1749,7 +1729,7 @@ where |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn build_language_id(&self, value: EncodedTerm<S::StrId>) -> Option<SmallStringOrId<S::StrId>> { |
|
|
|
fn build_language_id(&self, value: EncodedTerm) -> Option<SmallStringOrId> { |
|
|
|
let mut language = self.to_simple_string(value)?; |
|
|
|
let mut language = self.to_simple_string(value)?; |
|
|
|
language.make_ascii_lowercase(); |
|
|
|
language.make_ascii_lowercase(); |
|
|
|
self.build_string_id(LanguageTag::parse(language).ok()?.as_str()) |
|
|
|
self.build_string_id(LanguageTag::parse(language).ok()?.as_str()) |
|
|
@ -1757,9 +1737,9 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn to_argument_compatible_strings( |
|
|
|
fn to_argument_compatible_strings( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
arg1: EncodedTerm<S::StrId>, |
|
|
|
arg1: EncodedTerm, |
|
|
|
arg2: EncodedTerm<S::StrId>, |
|
|
|
arg2: EncodedTerm, |
|
|
|
) -> Option<(String, String, Option<SmallStringOrId<S::StrId>>)> { |
|
|
|
) -> Option<(String, String, Option<SmallStringOrId>)> { |
|
|
|
let (value1, language1) = self.to_string_and_language(arg1)?; |
|
|
|
let (value1, language1) = self.to_string_and_language(arg1)?; |
|
|
|
let (value2, language2) = self.to_string_and_language(arg2)?; |
|
|
|
let (value2, language2) = self.to_string_and_language(arg2)?; |
|
|
|
if language2.is_none() || language1 == language2 { |
|
|
|
if language2.is_none() || language1 == language2 { |
|
|
@ -1769,11 +1749,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn compile_pattern( |
|
|
|
fn compile_pattern(&self, pattern: EncodedTerm, flags: Option<EncodedTerm>) -> Option<Regex> { |
|
|
|
&self, |
|
|
|
|
|
|
|
pattern: EncodedTerm<S::StrId>, |
|
|
|
|
|
|
|
flags: Option<EncodedTerm<S::StrId>>, |
|
|
|
|
|
|
|
) -> Option<Regex> { |
|
|
|
|
|
|
|
// TODO Avoid to compile the regex each time
|
|
|
|
// TODO Avoid to compile the regex each time
|
|
|
|
let pattern = self.to_simple_string(pattern)?; |
|
|
|
let pattern = self.to_simple_string(pattern)?; |
|
|
|
let mut regex_builder = RegexBuilder::new(&pattern); |
|
|
|
let mut regex_builder = RegexBuilder::new(&pattern); |
|
|
@ -1804,9 +1780,9 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn parse_numeric_operands( |
|
|
|
fn parse_numeric_operands( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
e1: &PlanExpression<S::StrId>, |
|
|
|
e1: &PlanExpression, |
|
|
|
e2: &PlanExpression<S::StrId>, |
|
|
|
e2: &PlanExpression, |
|
|
|
tuple: &EncodedTuple<S::StrId>, |
|
|
|
tuple: &EncodedTuple, |
|
|
|
) -> Option<NumericBinaryOperands> { |
|
|
|
) -> Option<NumericBinaryOperands> { |
|
|
|
NumericBinaryOperands::new( |
|
|
|
NumericBinaryOperands::new( |
|
|
|
self.eval_expression(e1, tuple)?, |
|
|
|
self.eval_expression(e1, tuple)?, |
|
|
@ -1816,7 +1792,7 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn decode_bindings( |
|
|
|
fn decode_bindings( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
iter: EncodedTuplesIterator<S::StrId>, |
|
|
|
iter: EncodedTuplesIterator, |
|
|
|
variables: Rc<Vec<Variable>>, |
|
|
|
variables: Rc<Vec<Variable>>, |
|
|
|
) -> QuerySolutionIter { |
|
|
|
) -> QuerySolutionIter { |
|
|
|
let eval = self.clone(); |
|
|
|
let eval = self.clone(); |
|
|
@ -1840,7 +1816,7 @@ where |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
variables: Rc<Vec<Variable>>, |
|
|
|
variables: Rc<Vec<Variable>>, |
|
|
|
iter: QuerySolutionIter, |
|
|
|
iter: QuerySolutionIter, |
|
|
|
) -> EncodedTuplesIterator<S::StrId> { |
|
|
|
) -> EncodedTuplesIterator { |
|
|
|
let eval = self.clone(); |
|
|
|
let eval = self.clone(); |
|
|
|
Box::new(iter.map(move |solution| { |
|
|
|
Box::new(iter.map(move |solution| { |
|
|
|
let mut encoder = eval.dataset.as_ref(); |
|
|
|
let mut encoder = eval.dataset.as_ref(); |
|
|
@ -1862,7 +1838,7 @@ where |
|
|
|
clippy::cast_possible_truncation, |
|
|
|
clippy::cast_possible_truncation, |
|
|
|
clippy::cast_precision_loss |
|
|
|
clippy::cast_precision_loss |
|
|
|
)] |
|
|
|
)] |
|
|
|
fn equals(&self, a: EncodedTerm<S::StrId>, b: EncodedTerm<S::StrId>) -> Option<bool> { |
|
|
|
fn equals(&self, a: EncodedTerm, b: EncodedTerm) -> Option<bool> { |
|
|
|
match a { |
|
|
|
match a { |
|
|
|
EncodedTerm::DefaultGraph |
|
|
|
EncodedTerm::DefaultGraph |
|
|
|
| EncodedTerm::NamedNode { .. } |
|
|
|
| EncodedTerm::NamedNode { .. } |
|
|
@ -2012,9 +1988,9 @@ where |
|
|
|
|
|
|
|
|
|
|
|
fn cmp_according_to_expression( |
|
|
|
fn cmp_according_to_expression( |
|
|
|
&self, |
|
|
|
&self, |
|
|
|
tuple_a: &EncodedTuple<S::StrId>, |
|
|
|
tuple_a: &EncodedTuple, |
|
|
|
tuple_b: &EncodedTuple<S::StrId>, |
|
|
|
tuple_b: &EncodedTuple, |
|
|
|
expression: &PlanExpression<S::StrId>, |
|
|
|
expression: &PlanExpression, |
|
|
|
) -> Ordering { |
|
|
|
) -> Ordering { |
|
|
|
self.cmp_terms( |
|
|
|
self.cmp_terms( |
|
|
|
self.eval_expression(expression, tuple_a), |
|
|
|
self.eval_expression(expression, tuple_a), |
|
|
@ -2022,11 +1998,7 @@ where |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn cmp_terms( |
|
|
|
fn cmp_terms(&self, a: Option<EncodedTerm>, b: Option<EncodedTerm>) -> Ordering { |
|
|
|
&self, |
|
|
|
|
|
|
|
a: Option<EncodedTerm<S::StrId>>, |
|
|
|
|
|
|
|
b: Option<EncodedTerm<S::StrId>>, |
|
|
|
|
|
|
|
) -> Ordering { |
|
|
|
|
|
|
|
match (a, b) { |
|
|
|
match (a, b) { |
|
|
|
(Some(a), Some(b)) => match a { |
|
|
|
(Some(a), Some(b)) => match a { |
|
|
|
_ if a.is_blank_node() => match b { |
|
|
|
_ if a.is_blank_node() => match b { |
|
|
@ -2052,11 +2024,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[allow(clippy::cast_precision_loss)] |
|
|
|
#[allow(clippy::cast_precision_loss)] |
|
|
|
fn partial_cmp_literals( |
|
|
|
fn partial_cmp_literals(&self, a: EncodedTerm, b: EncodedTerm) -> Option<Ordering> { |
|
|
|
&self, |
|
|
|
|
|
|
|
a: EncodedTerm<S::StrId>, |
|
|
|
|
|
|
|
b: EncodedTerm<S::StrId>, |
|
|
|
|
|
|
|
) -> Option<Ordering> { |
|
|
|
|
|
|
|
match a { |
|
|
|
match a { |
|
|
|
EncodedTerm::SmallStringLiteral(a) => match b { |
|
|
|
EncodedTerm::SmallStringLiteral(a) => match b { |
|
|
|
EncodedTerm::SmallStringLiteral(b) => a.partial_cmp(&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<Ordering> { |
|
|
|
fn compare_str_ids(&self, a: StrHash, b: StrHash) -> Option<Ordering> { |
|
|
|
Some( |
|
|
|
Some( |
|
|
|
self.dataset |
|
|
|
self.dataset |
|
|
|
.get_str(a) |
|
|
|
.get_str(a) |
|
|
@ -2183,25 +2151,21 @@ where |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn compare_str_id_str(&self, a: S::StrId, b: &str) -> Option<Ordering> { |
|
|
|
fn compare_str_id_str(&self, a: StrHash, b: &str) -> Option<Ordering> { |
|
|
|
Some(self.dataset.get_str(a).ok()??.as_str().cmp(b)) |
|
|
|
Some(self.dataset.get_str(a).ok()??.as_str().cmp(b)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn compare_str_str_id(&self, a: &str, b: S::StrId) -> Option<Ordering> { |
|
|
|
fn compare_str_str_id(&self, a: &str, b: StrHash) -> Option<Ordering> { |
|
|
|
Some(a.cmp(self.dataset.get_str(b).ok()??.as_str())) |
|
|
|
Some(a.cmp(self.dataset.get_str(b).ok()??.as_str())) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn hash<H: Digest>( |
|
|
|
fn hash<H: Digest>(&self, arg: &PlanExpression, tuple: &EncodedTuple) -> Option<EncodedTerm> { |
|
|
|
&self, |
|
|
|
|
|
|
|
arg: &PlanExpression<S::StrId>, |
|
|
|
|
|
|
|
tuple: &EncodedTuple<S::StrId>, |
|
|
|
|
|
|
|
) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
|
|
|
|
let input = self.to_simple_string(self.eval_expression(arg, tuple)?)?; |
|
|
|
let input = self.to_simple_string(self.eval_expression(arg, tuple)?)?; |
|
|
|
let hash = hex::encode(H::new().chain(input.as_str()).finalize()); |
|
|
|
let hash = hex::encode(H::new().chain(input.as_str()).finalize()); |
|
|
|
self.build_string_literal(&hash) |
|
|
|
self.build_string_literal(&hash) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn datatype(&self, value: EncodedTerm<S::StrId>) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
fn datatype(&self, value: EncodedTerm) -> Option<EncodedTerm> { |
|
|
|
//TODO: optimize?
|
|
|
|
//TODO: optimize?
|
|
|
|
match value { |
|
|
|
match value { |
|
|
|
EncodedTerm::NamedNode { .. } |
|
|
|
EncodedTerm::NamedNode { .. } |
|
|
@ -2269,7 +2233,7 @@ enum NumericBinaryOperands { |
|
|
|
|
|
|
|
|
|
|
|
impl NumericBinaryOperands { |
|
|
|
impl NumericBinaryOperands { |
|
|
|
#[allow(clippy::cast_precision_loss)] |
|
|
|
#[allow(clippy::cast_precision_loss)] |
|
|
|
fn new<I: StrId>(a: EncodedTerm<I>, b: EncodedTerm<I>) -> Option<Self> { |
|
|
|
fn new(a: EncodedTerm, b: EncodedTerm) -> Option<Self> { |
|
|
|
match (a, b) { |
|
|
|
match (a, b) { |
|
|
|
(EncodedTerm::FloatLiteral(v1), EncodedTerm::FloatLiteral(v2)) => { |
|
|
|
(EncodedTerm::FloatLiteral(v1), EncodedTerm::FloatLiteral(v2)) => { |
|
|
|
Some(NumericBinaryOperands::Float(v1, v2)) |
|
|
|
Some(NumericBinaryOperands::Float(v1, v2)) |
|
|
@ -2387,32 +2351,25 @@ impl NumericBinaryOperands { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_pattern_value<I: StrId>( |
|
|
|
fn get_pattern_value(selector: &PatternValue, tuple: &EncodedTuple) -> Option<EncodedTerm> { |
|
|
|
selector: &PatternValue<I>, |
|
|
|
|
|
|
|
tuple: &EncodedTuple<I>, |
|
|
|
|
|
|
|
) -> Option<EncodedTerm<I>> { |
|
|
|
|
|
|
|
match selector { |
|
|
|
match selector { |
|
|
|
PatternValue::Constant(term) => Some(*term), |
|
|
|
PatternValue::Constant(term) => Some(*term), |
|
|
|
PatternValue::Variable(v) => tuple.get(*v), |
|
|
|
PatternValue::Variable(v) => tuple.get(*v), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn put_pattern_value<I: StrId>( |
|
|
|
fn put_pattern_value(selector: &PatternValue, value: EncodedTerm, tuple: &mut EncodedTuple) { |
|
|
|
selector: &PatternValue<I>, |
|
|
|
|
|
|
|
value: EncodedTerm<I>, |
|
|
|
|
|
|
|
tuple: &mut EncodedTuple<I>, |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
match selector { |
|
|
|
match selector { |
|
|
|
PatternValue::Constant(_) => (), |
|
|
|
PatternValue::Constant(_) => (), |
|
|
|
PatternValue::Variable(v) => tuple.set(*v, value), |
|
|
|
PatternValue::Variable(v) => tuple.set(*v, value), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn put_variable_value<I: StrId>( |
|
|
|
fn put_variable_value( |
|
|
|
selector: &Variable, |
|
|
|
selector: &Variable, |
|
|
|
variables: &[Variable], |
|
|
|
variables: &[Variable], |
|
|
|
value: EncodedTerm<I>, |
|
|
|
value: EncodedTerm, |
|
|
|
tuple: &mut EncodedTuple<I>, |
|
|
|
tuple: &mut EncodedTuple, |
|
|
|
) { |
|
|
|
) { |
|
|
|
for (i, v) in variables.iter().enumerate() { |
|
|
|
for (i, v) in variables.iter().enumerate() { |
|
|
|
if selector == v { |
|
|
|
if selector == v { |
|
|
@ -2422,17 +2379,13 @@ fn put_variable_value<I: StrId>( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn unbind_variables<I: StrId>(binding: &mut EncodedTuple<I>, variables: &[usize]) { |
|
|
|
fn unbind_variables(binding: &mut EncodedTuple, variables: &[usize]) { |
|
|
|
for var in variables { |
|
|
|
for var in variables { |
|
|
|
binding.unset(*var) |
|
|
|
binding.unset(*var) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn combine_tuples<I: StrId>( |
|
|
|
fn combine_tuples(mut a: EncodedTuple, b: &EncodedTuple, vars: &[usize]) -> Option<EncodedTuple> { |
|
|
|
mut a: EncodedTuple<I>, |
|
|
|
|
|
|
|
b: &EncodedTuple<I>, |
|
|
|
|
|
|
|
vars: &[usize], |
|
|
|
|
|
|
|
) -> Option<EncodedTuple<I>> { |
|
|
|
|
|
|
|
for var in vars { |
|
|
|
for var in vars { |
|
|
|
if let Some(b_value) = b.get(*var) { |
|
|
|
if let Some(b_value) = b.get(*var) { |
|
|
|
if let Some(a_value) = a.get(*var) { |
|
|
|
if let Some(a_value) = a.get(*var) { |
|
|
@ -2447,10 +2400,7 @@ fn combine_tuples<I: StrId>( |
|
|
|
Some(a) |
|
|
|
Some(a) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn are_compatible_and_not_disjointed<I: StrId>( |
|
|
|
pub fn are_compatible_and_not_disjointed(a: &EncodedTuple, b: &EncodedTuple) -> bool { |
|
|
|
a: &EncodedTuple<I>, |
|
|
|
|
|
|
|
b: &EncodedTuple<I>, |
|
|
|
|
|
|
|
) -> bool { |
|
|
|
|
|
|
|
let mut found_intersection = false; |
|
|
|
let mut found_intersection = false; |
|
|
|
for (a_value, b_value) in a.iter().zip(b.iter()) { |
|
|
|
for (a_value, b_value) in a.iter().zip(b.iter()) { |
|
|
|
if let (Some(a_value), Some(b_value)) = (a_value, b_value) { |
|
|
|
if let (Some(a_value), Some(b_value)) = (a_value, b_value) { |
|
|
@ -2463,16 +2413,16 @@ pub fn are_compatible_and_not_disjointed<I: StrId>( |
|
|
|
found_intersection |
|
|
|
found_intersection |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct JoinIterator<I: StrId> { |
|
|
|
struct JoinIterator { |
|
|
|
left: Vec<EncodedTuple<I>>, |
|
|
|
left: Vec<EncodedTuple>, |
|
|
|
right_iter: EncodedTuplesIterator<I>, |
|
|
|
right_iter: EncodedTuplesIterator, |
|
|
|
buffered_results: Vec<Result<EncodedTuple<I>, EvaluationError>>, |
|
|
|
buffered_results: Vec<Result<EncodedTuple, EvaluationError>>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> Iterator for JoinIterator<I> { |
|
|
|
impl Iterator for JoinIterator { |
|
|
|
type Item = Result<EncodedTuple<I>, EvaluationError>; |
|
|
|
type Item = Result<EncodedTuple, EvaluationError>; |
|
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple<I>, EvaluationError>> { |
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple, EvaluationError>> { |
|
|
|
loop { |
|
|
|
loop { |
|
|
|
if let Some(result) = self.buffered_results.pop() { |
|
|
|
if let Some(result) = self.buffered_results.pop() { |
|
|
|
return Some(result); |
|
|
|
return Some(result); |
|
|
@ -2490,15 +2440,15 @@ impl<I: StrId> Iterator for JoinIterator<I> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct AntiJoinIterator<I: StrId> { |
|
|
|
struct AntiJoinIterator { |
|
|
|
left_iter: EncodedTuplesIterator<I>, |
|
|
|
left_iter: EncodedTuplesIterator, |
|
|
|
right: Vec<EncodedTuple<I>>, |
|
|
|
right: Vec<EncodedTuple>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> Iterator for AntiJoinIterator<I> { |
|
|
|
impl Iterator for AntiJoinIterator { |
|
|
|
type Item = Result<EncodedTuple<I>, EvaluationError>; |
|
|
|
type Item = Result<EncodedTuple, EvaluationError>; |
|
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple<I>, EvaluationError>> { |
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple, EvaluationError>> { |
|
|
|
loop { |
|
|
|
loop { |
|
|
|
match self.left_iter.next()? { |
|
|
|
match self.left_iter.next()? { |
|
|
|
Ok(left_tuple) => { |
|
|
|
Ok(left_tuple) => { |
|
|
@ -2517,18 +2467,18 @@ impl<I: StrId> Iterator for AntiJoinIterator<I> { |
|
|
|
|
|
|
|
|
|
|
|
struct LeftJoinIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
struct LeftJoinIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
right_plan: Rc<PlanNode<S::StrId>>, |
|
|
|
right_plan: Rc<PlanNode>, |
|
|
|
left_iter: EncodedTuplesIterator<S::StrId>, |
|
|
|
left_iter: EncodedTuplesIterator, |
|
|
|
current_right: EncodedTuplesIterator<S::StrId>, |
|
|
|
current_right: EncodedTuplesIterator, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for LeftJoinIterator<S> |
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for LeftJoinIterator<S> |
|
|
|
where |
|
|
|
where |
|
|
|
for<'a> &'a S: StrContainer<StrId = S::StrId>, |
|
|
|
for<'a> &'a S: StrContainer, |
|
|
|
{ |
|
|
|
{ |
|
|
|
type Item = Result<EncodedTuple<S::StrId>, EvaluationError>; |
|
|
|
type Item = Result<EncodedTuple, EvaluationError>; |
|
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple<S::StrId>, EvaluationError>> { |
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple, EvaluationError>> { |
|
|
|
if let Some(tuple) = self.current_right.next() { |
|
|
|
if let Some(tuple) = self.current_right.next() { |
|
|
|
return Some(tuple); |
|
|
|
return Some(tuple); |
|
|
|
} |
|
|
|
} |
|
|
@ -2548,20 +2498,20 @@ where |
|
|
|
|
|
|
|
|
|
|
|
struct BadLeftJoinIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
struct BadLeftJoinIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
right_plan: Rc<PlanNode<S::StrId>>, |
|
|
|
right_plan: Rc<PlanNode>, |
|
|
|
left_iter: EncodedTuplesIterator<S::StrId>, |
|
|
|
left_iter: EncodedTuplesIterator, |
|
|
|
current_left: Option<EncodedTuple<S::StrId>>, |
|
|
|
current_left: Option<EncodedTuple>, |
|
|
|
current_right: EncodedTuplesIterator<S::StrId>, |
|
|
|
current_right: EncodedTuplesIterator, |
|
|
|
problem_vars: Rc<Vec<usize>>, |
|
|
|
problem_vars: Rc<Vec<usize>>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for BadLeftJoinIterator<S> |
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for BadLeftJoinIterator<S> |
|
|
|
where |
|
|
|
where |
|
|
|
for<'a> &'a S: StrContainer<StrId = S::StrId>, |
|
|
|
for<'a> &'a S: StrContainer, |
|
|
|
{ |
|
|
|
{ |
|
|
|
type Item = Result<EncodedTuple<S::StrId>, EvaluationError>; |
|
|
|
type Item = Result<EncodedTuple, EvaluationError>; |
|
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple<S::StrId>, EvaluationError>> { |
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple, EvaluationError>> { |
|
|
|
while let Some(right_tuple) = self.current_right.next() { |
|
|
|
while let Some(right_tuple) = self.current_right.next() { |
|
|
|
match right_tuple { |
|
|
|
match right_tuple { |
|
|
|
Ok(right_tuple) => { |
|
|
|
Ok(right_tuple) => { |
|
|
@ -2603,19 +2553,19 @@ where |
|
|
|
|
|
|
|
|
|
|
|
struct UnionIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
struct UnionIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
plans: Vec<Rc<PlanNode<S::StrId>>>, |
|
|
|
plans: Vec<Rc<PlanNode>>, |
|
|
|
input: EncodedTuple<S::StrId>, |
|
|
|
input: EncodedTuple, |
|
|
|
current_iterator: EncodedTuplesIterator<S::StrId>, |
|
|
|
current_iterator: EncodedTuplesIterator, |
|
|
|
current_plan: usize, |
|
|
|
current_plan: usize, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for UnionIterator<S> |
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for UnionIterator<S> |
|
|
|
where |
|
|
|
where |
|
|
|
for<'a> &'a S: StrContainer<StrId = S::StrId>, |
|
|
|
for<'a> &'a S: StrContainer, |
|
|
|
{ |
|
|
|
{ |
|
|
|
type Item = Result<EncodedTuple<S::StrId>, EvaluationError>; |
|
|
|
type Item = Result<EncodedTuple, EvaluationError>; |
|
|
|
|
|
|
|
|
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple<S::StrId>, EvaluationError>> { |
|
|
|
fn next(&mut self) -> Option<Result<EncodedTuple, EvaluationError>> { |
|
|
|
loop { |
|
|
|
loop { |
|
|
|
if let Some(tuple) = self.current_iterator.next() { |
|
|
|
if let Some(tuple) = self.current_iterator.next() { |
|
|
|
return Some(tuple); |
|
|
|
return Some(tuple); |
|
|
@ -2633,10 +2583,10 @@ where |
|
|
|
|
|
|
|
|
|
|
|
struct ConstructIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
struct ConstructIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
iter: EncodedTuplesIterator<S::StrId>, |
|
|
|
iter: EncodedTuplesIterator, |
|
|
|
template: Vec<TripleTemplate<S::StrId>>, |
|
|
|
template: Vec<TripleTemplate>, |
|
|
|
buffered_results: Vec<Result<Triple, EvaluationError>>, |
|
|
|
buffered_results: Vec<Result<Triple, EvaluationError>>, |
|
|
|
bnodes: Vec<EncodedTerm<S::StrId>>, |
|
|
|
bnodes: Vec<EncodedTerm>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for ConstructIterator<S> { |
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for ConstructIterator<S> { |
|
|
@ -2672,11 +2622,11 @@ impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for Co |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_triple_template_value<I: StrId>( |
|
|
|
fn get_triple_template_value( |
|
|
|
selector: &TripleTemplateValue<I>, |
|
|
|
selector: &TripleTemplateValue, |
|
|
|
tuple: &EncodedTuple<I>, |
|
|
|
tuple: &EncodedTuple, |
|
|
|
bnodes: &mut Vec<EncodedTerm<I>>, |
|
|
|
bnodes: &mut Vec<EncodedTerm>, |
|
|
|
) -> Option<EncodedTerm<I>> { |
|
|
|
) -> Option<EncodedTerm> { |
|
|
|
match selector { |
|
|
|
match selector { |
|
|
|
TripleTemplateValue::Constant(term) => Some(*term), |
|
|
|
TripleTemplateValue::Constant(term) => Some(*term), |
|
|
|
TripleTemplateValue::Variable(v) => tuple.get(*v), |
|
|
|
TripleTemplateValue::Variable(v) => tuple.get(*v), |
|
|
@ -2689,15 +2639,15 @@ fn get_triple_template_value<I: StrId>( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn new_bnode<I: StrId>() -> EncodedTerm<I> { |
|
|
|
fn new_bnode() -> EncodedTerm { |
|
|
|
EncodedTerm::NumericalBlankNode { id: random() } |
|
|
|
EncodedTerm::NumericalBlankNode { id: random() } |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn decode_triple<D: Decoder>( |
|
|
|
fn decode_triple<D: Decoder>( |
|
|
|
decoder: &D, |
|
|
|
decoder: &D, |
|
|
|
subject: EncodedTerm<D::StrId>, |
|
|
|
subject: EncodedTerm, |
|
|
|
predicate: EncodedTerm<D::StrId>, |
|
|
|
predicate: EncodedTerm, |
|
|
|
object: EncodedTerm<D::StrId>, |
|
|
|
object: EncodedTerm, |
|
|
|
) -> Result<Triple, EvaluationError> { |
|
|
|
) -> Result<Triple, EvaluationError> { |
|
|
|
Ok(Triple::new( |
|
|
|
Ok(Triple::new( |
|
|
|
decoder.decode_named_or_blank_node(subject)?, |
|
|
|
decoder.decode_named_or_blank_node(subject)?, |
|
|
@ -2708,8 +2658,8 @@ fn decode_triple<D: Decoder>( |
|
|
|
|
|
|
|
|
|
|
|
struct DescribeIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
struct DescribeIterator<S: ReadableEncodedStore + 'static> { |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
iter: EncodedTuplesIterator<S::StrId>, |
|
|
|
iter: EncodedTuplesIterator, |
|
|
|
quads: Box<dyn Iterator<Item = Result<EncodedQuad<S::StrId>, EvaluationError>>>, |
|
|
|
quads: Box<dyn Iterator<Item = Result<EncodedQuad, EvaluationError>>>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for DescribeIterator<S> { |
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for DescribeIterator<S> { |
|
|
@ -2894,19 +2844,19 @@ impl< |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
trait Accumulator<I: StrId> { |
|
|
|
trait Accumulator { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm<I>>); |
|
|
|
fn add(&mut self, element: Option<EncodedTerm>); |
|
|
|
|
|
|
|
|
|
|
|
fn state(&self) -> Option<EncodedTerm<I>>; |
|
|
|
fn state(&self) -> Option<EncodedTerm>; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Default, Debug)] |
|
|
|
#[derive(Default, Debug)] |
|
|
|
struct DistinctAccumulator<I: StrId, T: Accumulator<I>> { |
|
|
|
struct DistinctAccumulator<T: Accumulator> { |
|
|
|
seen: HashSet<Option<EncodedTerm<I>>>, |
|
|
|
seen: HashSet<Option<EncodedTerm>>, |
|
|
|
inner: T, |
|
|
|
inner: T, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId, T: Accumulator<I>> DistinctAccumulator<I, T> { |
|
|
|
impl<T: Accumulator> DistinctAccumulator<T> { |
|
|
|
fn new(inner: T) -> Self { |
|
|
|
fn new(inner: T) -> Self { |
|
|
|
Self { |
|
|
|
Self { |
|
|
|
seen: HashSet::default(), |
|
|
|
seen: HashSet::default(), |
|
|
@ -2915,14 +2865,14 @@ impl<I: StrId, T: Accumulator<I>> DistinctAccumulator<I, T> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId, T: Accumulator<I>> Accumulator<I> for DistinctAccumulator<I, T> { |
|
|
|
impl<T: Accumulator> Accumulator for DistinctAccumulator<T> { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm<I>>) { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm>) { |
|
|
|
if self.seen.insert(element) { |
|
|
|
if self.seen.insert(element) { |
|
|
|
self.inner.add(element) |
|
|
|
self.inner.add(element) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn state(&self) -> Option<EncodedTerm<I>> { |
|
|
|
fn state(&self) -> Option<EncodedTerm> { |
|
|
|
self.inner.state() |
|
|
|
self.inner.state() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -2932,22 +2882,22 @@ struct CountAccumulator { |
|
|
|
count: i64, |
|
|
|
count: i64, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> Accumulator<I> for CountAccumulator { |
|
|
|
impl Accumulator for CountAccumulator { |
|
|
|
fn add(&mut self, _element: Option<EncodedTerm<I>>) { |
|
|
|
fn add(&mut self, _element: Option<EncodedTerm>) { |
|
|
|
self.count += 1; |
|
|
|
self.count += 1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn state(&self) -> Option<EncodedTerm<I>> { |
|
|
|
fn state(&self) -> Option<EncodedTerm> { |
|
|
|
Some(self.count.into()) |
|
|
|
Some(self.count.into()) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
|
struct SumAccumulator<I: StrId> { |
|
|
|
struct SumAccumulator { |
|
|
|
sum: Option<EncodedTerm<I>>, |
|
|
|
sum: Option<EncodedTerm>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> Default for SumAccumulator<I> { |
|
|
|
impl Default for SumAccumulator { |
|
|
|
fn default() -> Self { |
|
|
|
fn default() -> Self { |
|
|
|
Self { |
|
|
|
Self { |
|
|
|
sum: Some(0.into()), |
|
|
|
sum: Some(0.into()), |
|
|
@ -2955,8 +2905,8 @@ impl<I: StrId> Default for SumAccumulator<I> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> Accumulator<I> for SumAccumulator<I> { |
|
|
|
impl Accumulator for SumAccumulator { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm<I>>) { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm>) { |
|
|
|
if let Some(sum) = self.sum { |
|
|
|
if let Some(sum) = self.sum { |
|
|
|
if let Some(operands) = element.and_then(|e| NumericBinaryOperands::new(sum, e)) { |
|
|
|
if let Some(operands) = element.and_then(|e| NumericBinaryOperands::new(sum, e)) { |
|
|
|
//TODO: unify with addition?
|
|
|
|
//TODO: unify with addition?
|
|
|
@ -2974,18 +2924,18 @@ impl<I: StrId> Accumulator<I> for SumAccumulator<I> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn state(&self) -> Option<EncodedTerm<I>> { |
|
|
|
fn state(&self) -> Option<EncodedTerm> { |
|
|
|
self.sum |
|
|
|
self.sum |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
|
struct AvgAccumulator<I: StrId> { |
|
|
|
struct AvgAccumulator { |
|
|
|
sum: SumAccumulator<I>, |
|
|
|
sum: SumAccumulator, |
|
|
|
count: CountAccumulator, |
|
|
|
count: CountAccumulator, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> Default for AvgAccumulator<I> { |
|
|
|
impl Default for AvgAccumulator { |
|
|
|
fn default() -> Self { |
|
|
|
fn default() -> Self { |
|
|
|
Self { |
|
|
|
Self { |
|
|
|
sum: SumAccumulator::default(), |
|
|
|
sum: SumAccumulator::default(), |
|
|
@ -2994,13 +2944,13 @@ impl<I: StrId> Default for AvgAccumulator<I> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> Accumulator<I> for AvgAccumulator<I> { |
|
|
|
impl Accumulator for AvgAccumulator { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm<I>>) { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm>) { |
|
|
|
self.sum.add(element); |
|
|
|
self.sum.add(element); |
|
|
|
self.count.add(element); |
|
|
|
self.count.add(element); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn state(&self) -> Option<EncodedTerm<I>> { |
|
|
|
fn state(&self) -> Option<EncodedTerm> { |
|
|
|
let sum = self.sum.state()?; |
|
|
|
let sum = self.sum.state()?; |
|
|
|
let count = self.count.state()?; |
|
|
|
let count = self.count.state()?; |
|
|
|
if count == EncodedTerm::from(0) { |
|
|
|
if count == EncodedTerm::from(0) { |
|
|
@ -3024,7 +2974,7 @@ impl<I: StrId> Accumulator<I> for AvgAccumulator<I> { |
|
|
|
#[allow(clippy::option_option)] |
|
|
|
#[allow(clippy::option_option)] |
|
|
|
struct MinAccumulator<S: ReadableEncodedStore + 'static> { |
|
|
|
struct MinAccumulator<S: ReadableEncodedStore + 'static> { |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
min: Option<Option<EncodedTerm<S::StrId>>>, |
|
|
|
min: Option<Option<EncodedTerm>>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore + 'static> MinAccumulator<S> { |
|
|
|
impl<S: ReadableEncodedStore + 'static> MinAccumulator<S> { |
|
|
@ -3033,12 +2983,11 @@ impl<S: ReadableEncodedStore + 'static> MinAccumulator<S> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Accumulator<S::StrId> |
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Accumulator for MinAccumulator<S> |
|
|
|
for MinAccumulator<S> |
|
|
|
|
|
|
|
where |
|
|
|
where |
|
|
|
for<'a> &'a S: StrContainer<StrId = S::StrId>, |
|
|
|
for<'a> &'a S: StrContainer, |
|
|
|
{ |
|
|
|
{ |
|
|
|
fn add(&mut self, element: Option<EncodedTerm<S::StrId>>) { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm>) { |
|
|
|
if let Some(min) = self.min { |
|
|
|
if let Some(min) = self.min { |
|
|
|
if self.eval.cmp_terms(element, min) == Ordering::Less { |
|
|
|
if self.eval.cmp_terms(element, min) == Ordering::Less { |
|
|
|
self.min = Some(element) |
|
|
|
self.min = Some(element) |
|
|
@ -3048,7 +2997,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn state(&self) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
fn state(&self) -> Option<EncodedTerm> { |
|
|
|
self.min.and_then(|v| v) |
|
|
|
self.min.and_then(|v| v) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -3056,7 +3005,7 @@ where |
|
|
|
#[allow(clippy::option_option)] |
|
|
|
#[allow(clippy::option_option)] |
|
|
|
struct MaxAccumulator<S: ReadableEncodedStore + 'static> { |
|
|
|
struct MaxAccumulator<S: ReadableEncodedStore + 'static> { |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
max: Option<Option<EncodedTerm<S::StrId>>>, |
|
|
|
max: Option<Option<EncodedTerm>>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore + 'static> MaxAccumulator<S> { |
|
|
|
impl<S: ReadableEncodedStore + 'static> MaxAccumulator<S> { |
|
|
@ -3065,12 +3014,11 @@ impl<S: ReadableEncodedStore + 'static> MaxAccumulator<S> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Accumulator<S::StrId> |
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Accumulator for MaxAccumulator<S> |
|
|
|
for MaxAccumulator<S> |
|
|
|
|
|
|
|
where |
|
|
|
where |
|
|
|
for<'a> &'a S: StrContainer<StrId = S::StrId>, |
|
|
|
for<'a> &'a S: StrContainer, |
|
|
|
{ |
|
|
|
{ |
|
|
|
fn add(&mut self, element: Option<EncodedTerm<S::StrId>>) { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm>) { |
|
|
|
if let Some(max) = self.max { |
|
|
|
if let Some(max) = self.max { |
|
|
|
if self.eval.cmp_terms(element, max) == Ordering::Greater { |
|
|
|
if self.eval.cmp_terms(element, max) == Ordering::Greater { |
|
|
|
self.max = Some(element) |
|
|
|
self.max = Some(element) |
|
|
@ -3080,30 +3028,30 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn state(&self) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
fn state(&self) -> Option<EncodedTerm> { |
|
|
|
self.max.and_then(|v| v) |
|
|
|
self.max.and_then(|v| v) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug)] |
|
|
|
#[derive(Debug)] |
|
|
|
struct SampleAccumulator<I: StrId> { |
|
|
|
struct SampleAccumulator { |
|
|
|
value: Option<EncodedTerm<I>>, |
|
|
|
value: Option<EncodedTerm>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> Default for SampleAccumulator<I> { |
|
|
|
impl Default for SampleAccumulator { |
|
|
|
fn default() -> Self { |
|
|
|
fn default() -> Self { |
|
|
|
Self { value: None } |
|
|
|
Self { value: None } |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> Accumulator<I> for SampleAccumulator<I> { |
|
|
|
impl Accumulator for SampleAccumulator { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm<I>>) { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm>) { |
|
|
|
if element.is_some() { |
|
|
|
if element.is_some() { |
|
|
|
self.value = element |
|
|
|
self.value = element |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn state(&self) -> Option<EncodedTerm<I>> { |
|
|
|
fn state(&self) -> Option<EncodedTerm> { |
|
|
|
self.value |
|
|
|
self.value |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -3112,7 +3060,7 @@ impl<I: StrId> Accumulator<I> for SampleAccumulator<I> { |
|
|
|
struct GroupConcatAccumulator<S: ReadableEncodedStore + 'static> { |
|
|
|
struct GroupConcatAccumulator<S: ReadableEncodedStore + 'static> { |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
eval: SimpleEvaluator<S>, |
|
|
|
concat: Option<String>, |
|
|
|
concat: Option<String>, |
|
|
|
language: Option<Option<SmallStringOrId<S::StrId>>>, |
|
|
|
language: Option<Option<SmallStringOrId>>, |
|
|
|
separator: Rc<String>, |
|
|
|
separator: Rc<String>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3127,12 +3075,12 @@ impl<S: ReadableEncodedStore + 'static> GroupConcatAccumulator<S> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Accumulator<S::StrId> |
|
|
|
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Accumulator |
|
|
|
for GroupConcatAccumulator<S> |
|
|
|
for GroupConcatAccumulator<S> |
|
|
|
where |
|
|
|
where |
|
|
|
for<'a> &'a S: StrContainer<StrId = S::StrId>, |
|
|
|
for<'a> &'a S: StrContainer, |
|
|
|
{ |
|
|
|
{ |
|
|
|
fn add(&mut self, element: Option<EncodedTerm<S::StrId>>) { |
|
|
|
fn add(&mut self, element: Option<EncodedTerm>) { |
|
|
|
if let Some(concat) = self.concat.as_mut() { |
|
|
|
if let Some(concat) = self.concat.as_mut() { |
|
|
|
if let Some(element) = element { |
|
|
|
if let Some(element) = element { |
|
|
|
if let Some((value, e_language)) = self.eval.to_string_and_language(element) { |
|
|
|
if let Some((value, e_language)) = self.eval.to_string_and_language(element) { |
|
|
@ -3150,7 +3098,7 @@ where |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn state(&self) -> Option<EncodedTerm<S::StrId>> { |
|
|
|
fn state(&self) -> Option<EncodedTerm> { |
|
|
|
self.concat.as_ref().and_then(|result| { |
|
|
|
self.concat.as_ref().and_then(|result| { |
|
|
|
self.eval |
|
|
|
self.eval |
|
|
|
.build_plain_literal(result, self.language.and_then(|v| v)) |
|
|
|
.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)] |
|
|
|
#[derive(Eq, PartialEq, Clone, Copy)] |
|
|
|
enum SmallStringOrId<I: StrId> { |
|
|
|
enum SmallStringOrId { |
|
|
|
Small(SmallString), |
|
|
|
Small(SmallString), |
|
|
|
Big(I), |
|
|
|
Big(StrHash), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> From<SmallString> for SmallStringOrId<I> { |
|
|
|
impl From<SmallString> for SmallStringOrId { |
|
|
|
fn from(value: SmallString) -> Self { |
|
|
|
fn from(value: SmallString) -> Self { |
|
|
|
Self::Small(value) |
|
|
|
Self::Small(value) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> From<I> for SmallStringOrId<I> { |
|
|
|
impl From<StrHash> for SmallStringOrId { |
|
|
|
fn from(value: I) -> Self { |
|
|
|
fn from(value: StrHash) -> Self { |
|
|
|
Self::Big(value) |
|
|
|
Self::Big(value) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|