Drops generics on string ids

pull/171/head
Tpt 3 years ago
parent 7280823444
commit fe5bab8eb9
  1. 213
      lib/src/sparql/dataset.rs
  2. 404
      lib/src/sparql/eval.rs
  3. 2
      lib/src/sparql/mod.rs
  4. 306
      lib/src/sparql/plan.rs
  5. 66
      lib/src/sparql/plan_builder.rs
  6. 47
      lib/src/sparql/update.rs
  7. 5
      lib/src/store/binary_encoder.rs
  8. 48
      lib/src/store/mod.rs
  9. 363
      lib/src/store/numeric_encoder.rs
  10. 6
      lib/src/store/sled.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<S: ReadableEncodedStore> {
store: S,
extra: RefCell<HashMap<StrHash, String>>,
dataset: EncodedDatasetSpec<S::StrId>,
dataset: EncodedDatasetSpec,
}
impl<S: ReadableEncodedStore> DatasetView<S> {
@ -50,27 +49,68 @@ impl<S: ReadableEncodedStore> DatasetView<S> {
})
}
fn store_encoded_quads_for_pattern(
&self,
subject: Option<EncodedTerm>,
predicate: Option<EncodedTerm>,
object: Option<EncodedTerm>,
graph_name: Option<EncodedTerm>,
) -> impl Iterator<Item = Result<EncodedQuad, EvaluationError>> + 'static {
self.store
.encoded_quads_for_pattern(subject, predicate, object, graph_name)
.map(|t| t.map_err(|e| e.into()))
}
}
impl<S: ReadableEncodedStore> StrEncodingAware for DatasetView<S> {
type Error = EvaluationError;
}
impl<S: ReadableEncodedStore> StrLookup for DatasetView<S> {
fn get_str(&self, id: StrHash) -> Result<Option<String>, 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<Option<StrHash>, 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<S: ReadableEncodedStore + 'static> ReadableEncodedStore for DatasetView<S> {
type QuadsIter = Box<dyn Iterator<Item = Result<EncodedQuad, EvaluationError>>>;
type GraphsIter = Once<Result<EncodedTerm, EvaluationError>>;
#[allow(clippy::needless_collect)]
fn encoded_quads_for_pattern_in_dataset(
fn encoded_quads_for_pattern(
&self,
subject: Option<EncodedTerm<S::StrId>>,
predicate: Option<EncodedTerm<S::StrId>>,
object: Option<EncodedTerm<S::StrId>>,
graph_name: Option<EncodedTerm<S::StrId>>,
) -> Box<dyn Iterator<Item = Result<EncodedQuad<DatasetStrId<S::StrId>>, EvaluationError>>>
{
subject: Option<EncodedTerm>,
predicate: Option<EncodedTerm>,
object: Option<EncodedTerm>,
graph_name: Option<EncodedTerm>,
) -> Box<dyn Iterator<Item = Result<EncodedQuad, EvaluationError>>> {
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<S: ReadableEncodedStore> DatasetView<S> {
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<S: ReadableEncodedStore> DatasetView<S> {
)
})
.collect::<Vec<_>>();
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<S: ReadableEncodedStore> DatasetView<S> {
}))
}
} 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<S: ReadableEncodedStore> DatasetView<S> {
.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<S: ReadableEncodedStore> DatasetView<S> {
let iters = named_graphs
.iter()
.map(|graph_name| {
self.store.encoded_quads_for_pattern(
self.store_encoded_quads_for_pattern(
subject,
predicate,
object,
@ -136,13 +173,10 @@ impl<S: ReadableEncodedStore> DatasetView<S> {
)
})
.collect::<Vec<_>>();
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),
)
self.store_encoded_quads_for_pattern(subject, predicate, object, None)
.filter(|quad| match quad {
Err(_) => true,
Ok(quad) => quad.graph_name != EncodedTerm::DefaultGraph,
@ -150,56 +184,6 @@ impl<S: ReadableEncodedStore> DatasetView<S> {
)
}
}
}
impl<S: ReadableEncodedStore> StrEncodingAware for DatasetView<S> {
type Error = EvaluationError;
type StrId = DatasetStrId<S::StrId>;
}
impl<S: ReadableEncodedStore> StrLookup for DatasetView<S> {
fn get_str(&self, id: DatasetStrId<S::StrId>) -> Result<Option<String>, 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<Option<DatasetStrId<S::StrId>>, 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<S: ReadableEncodedStore> ReadableEncodedStore for DatasetView<S> {
type QuadsIter =
Box<dyn Iterator<Item = Result<EncodedQuad<DatasetStrId<S::StrId>>, EvaluationError>>>;
type GraphsIter = Once<Result<EncodedTerm<DatasetStrId<S::StrId>>, EvaluationError>>;
fn encoded_quads_for_pattern(
&self,
subject: Option<EncodedTerm<Self::StrId>>,
predicate: Option<EncodedTerm<Self::StrId>>,
object: Option<EncodedTerm<Self::StrId>>,
graph_name: Option<EncodedTerm<Self::StrId>>,
) -> Box<dyn Iterator<Item = Result<EncodedQuad<DatasetStrId<S::StrId>>, 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<S: ReadableEncodedStore> ReadableEncodedStore for DatasetView<S> {
)))
}
fn contains_encoded_named_graph(
&self,
_: EncodedTerm<Self::StrId>,
) -> Result<bool, EvaluationError> {
fn contains_encoded_named_graph(&self, _: EncodedTerm) -> Result<bool, EvaluationError> {
Err(EvaluationError::msg(
"Graphs lookup is not implemented by DatasetView",
))
}
}
fn map_iter<'a, I: StrId>(
iter: impl Iterator<Item = Result<EncodedQuad<I>, impl Into<EvaluationError>>> + 'a,
) -> impl Iterator<Item = Result<EncodedQuad<DatasetStrId<I>>, 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<I> = (
Option<EncodedTerm<I>>,
Option<EncodedTerm<I>>,
Option<EncodedTerm<I>>,
Option<EncodedTerm<I>>,
);
fn try_map_quad_pattern<I: StrId>(
subject: Option<EncodedTerm<DatasetStrId<I>>>,
predicate: Option<EncodedTerm<DatasetStrId<I>>>,
object: Option<EncodedTerm<DatasetStrId<I>>>,
graph_name: Option<EncodedTerm<DatasetStrId<I>>>,
) -> Option<QuadPattern<I>> {
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<T>(o: Option<Option<T>>) -> Option<Option<T>> {
match o {
Some(Some(v)) => Some(Some(v)),
Some(None) => None,
None => Some(None),
}
}
fn unwrap_store_id<I: StrId>(id: DatasetStrId<I>) -> Result<I, ()> {
match id {
DatasetStrId::Store(id) => Ok(id),
DatasetStrId::Temporary(_) => Err(()),
}
}
impl<'a, S: ReadableEncodedStore> StrContainer for &'a DatasetView<S> {
fn insert_str(&mut self, value: &str) -> Result<Self::StrId, EvaluationError> {
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<StrHash, EvaluationError> {
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<I: StrId> {
Store(I),
Temporary(StrHash),
}
impl<I: StrId> StrId for DatasetStrId<I> {}
struct EncodedDatasetSpec<I: StrId> {
default: Option<Vec<EncodedTerm<I>>>,
named: Option<Vec<EncodedTerm<I>>>,
struct EncodedDatasetSpec {
default: Option<Vec<EncodedTerm>>,
named: Option<Vec<EncodedTerm>>,
}

@ -29,7 +29,7 @@ use std::str;
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> {
dataset: Rc<S>,
@ -51,7 +51,7 @@ impl<S> Clone for SimpleEvaluator<S> {
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> SimpleEvaluator<S>
where
for<'a> &'a S: StrContainer<StrId = S::StrId>,
for<'a> &'a S: StrContainer,
{
pub fn new(
dataset: Rc<S>,
@ -68,7 +68,7 @@ where
pub fn evaluate_select_plan(
&self,
plan: &PlanNode<S::StrId>,
plan: &PlanNode,
variables: Rc<Vec<Variable>>,
) -> Result<QueryResults, EvaluationError> {
let iter = self.eval_plan(plan, EncodedTuple::with_capacity(variables.len()));
@ -77,10 +77,7 @@ where
))
}
pub fn evaluate_ask_plan(
&self,
plan: &PlanNode<S::StrId>,
) -> Result<QueryResults, EvaluationError> {
pub fn evaluate_ask_plan(&self, plan: &PlanNode) -> Result<QueryResults, EvaluationError> {
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<S::StrId>,
template: Vec<TripleTemplate<S::StrId>>,
plan: &PlanNode,
template: Vec<TripleTemplate>,
) -> Result<QueryResults, EvaluationError> {
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<S::StrId>,
) -> Result<QueryResults, EvaluationError> {
pub fn evaluate_describe_plan(&self, plan: &PlanNode) -> Result<QueryResults, EvaluationError> {
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<S::StrId>,
from: EncodedTuple<S::StrId>,
) -> EncodedTuplesIterator<S::StrId> {
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<Option<EncodedTerm<S::StrId>>>,
Vec<Box<dyn Accumulator<S::StrId>>>,
>::default();
let mut accumulators_for_group =
HashMap::<Vec<Option<EncodedTerm>>, Vec<Box<dyn Accumulator>>>::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<S::StrId>,
service_name: &PatternValue,
graph_pattern: &GraphPattern,
variables: Rc<Vec<Variable>>,
from: &EncodedTuple<S::StrId>,
) -> Result<EncodedTuplesIterator<S::StrId>, EvaluationError> {
from: &EncodedTuple,
) -> Result<EncodedTuplesIterator, EvaluationError> {
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<dyn Accumulator<S::StrId> + 'static> {
) -> Box<dyn Accumulator + 'static> {
match function {
PlanAggregationFunction::Count => {
if distinct {
@ -581,10 +569,10 @@ where
fn eval_path_from(
&self,
path: &PlanPropertyPath<S::StrId>,
start: EncodedTerm<S::StrId>,
graph_name: EncodedTerm<S::StrId>,
) -> Box<dyn Iterator<Item = Result<EncodedTerm<S::StrId>, EvaluationError>>> {
path: &PlanPropertyPath,
start: EncodedTerm,
graph_name: EncodedTerm,
) -> Box<dyn Iterator<Item = Result<EncodedTerm, EvaluationError>>> {
match path {
PlanPropertyPath::Path(p) => Box::new(
self.dataset
@ -644,10 +632,10 @@ where
fn eval_path_to(
&self,
path: &PlanPropertyPath<S::StrId>,
end: EncodedTerm<S::StrId>,
graph_name: EncodedTerm<S::StrId>,
) -> Box<dyn Iterator<Item = Result<EncodedTerm<S::StrId>, EvaluationError>>> {
path: &PlanPropertyPath,
end: EncodedTerm,
graph_name: EncodedTerm,
) -> Box<dyn Iterator<Item = Result<EncodedTerm, EvaluationError>>> {
match path {
PlanPropertyPath::Path(p) => Box::new(
self.dataset
@ -707,13 +695,9 @@ where
fn eval_open_path(
&self,
path: &PlanPropertyPath<S::StrId>,
graph_name: EncodedTerm<S::StrId>,
) -> Box<
dyn Iterator<
Item = Result<(EncodedTerm<S::StrId>, EncodedTerm<S::StrId>), EvaluationError>,
>,
> {
path: &PlanPropertyPath,
graph_name: EncodedTerm,
) -> Box<dyn Iterator<Item = Result<(EncodedTerm, EncodedTerm), EvaluationError>>> {
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<S::StrId>,
) -> impl Iterator<Item = Result<(EncodedTerm<S::StrId>, EncodedTerm<S::StrId>), EvaluationError>>
{
graph_name: EncodedTerm,
) -> impl Iterator<Item = Result<(EncodedTerm, EncodedTerm), EvaluationError>> {
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<S::StrId>,
tuple: &EncodedTuple<S::StrId>,
) -> Option<EncodedTerm<S::StrId>> {
expression: &PlanExpression,
tuple: &EncodedTuple,
) -> Option<EncodedTerm> {
match expression {
PlanExpression::Constant(t) => Some(*t),
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 {
EncodedTerm::BooleanLiteral(value) => Some(value),
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 {
EncodedTerm::DefaultGraph => None,
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 {
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<S::StrId>,
) -> Option<SmallStringOrId<S::StrId>> {
fn to_simple_string_id(&self, term: EncodedTerm) -> Option<SmallStringOrId> {
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<S::StrId>) -> Option<String> {
fn to_string(&self, term: EncodedTerm) -> Option<String> {
match term {
EncodedTerm::SmallStringLiteral(value)
| EncodedTerm::SmallSmallLangStringLiteral { value, .. }
@ -1653,8 +1633,8 @@ where
fn to_string_and_language(
&self,
term: EncodedTerm<S::StrId>,
) -> Option<(String, Option<SmallStringOrId<S::StrId>>)> {
term: EncodedTerm,
) -> Option<(String, Option<SmallStringOrId>)> {
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<EncodedTerm<S::StrId>> {
fn build_named_node(&self, iri: &str) -> Option<EncodedTerm> {
Some(EncodedTerm::NamedNode {
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)?))
}
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 {
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<S::StrId>,
) -> Option<EncodedTerm<S::StrId>> {
language_id: SmallStringOrId,
) -> Option<EncodedTerm> {
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<S::StrId>,
language_id: SmallStringOrId<S::StrId>,
) -> EncodedTerm<S::StrId> {
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<SmallStringOrId<S::StrId>>,
) -> Option<EncodedTerm<S::StrId>> {
language: Option<SmallStringOrId>,
) -> Option<EncodedTerm> {
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<SmallStringOrId<S::StrId>> {
fn build_string_id(&self, value: &str) -> Option<SmallStringOrId> {
Some(if let Ok(value) = SmallString::try_from(value) {
value.into()
} 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)?;
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<S::StrId>,
arg2: EncodedTerm<S::StrId>,
) -> Option<(String, String, Option<SmallStringOrId<S::StrId>>)> {
arg1: EncodedTerm,
arg2: EncodedTerm,
) -> Option<(String, String, Option<SmallStringOrId>)> {
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<S::StrId>,
flags: Option<EncodedTerm<S::StrId>>,
) -> Option<Regex> {
fn compile_pattern(&self, pattern: EncodedTerm, flags: Option<EncodedTerm>) -> Option<Regex> {
// 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<S::StrId>,
e2: &PlanExpression<S::StrId>,
tuple: &EncodedTuple<S::StrId>,
e1: &PlanExpression,
e2: &PlanExpression,
tuple: &EncodedTuple,
) -> Option<NumericBinaryOperands> {
NumericBinaryOperands::new(
self.eval_expression(e1, tuple)?,
@ -1816,7 +1792,7 @@ where
fn decode_bindings(
&self,
iter: EncodedTuplesIterator<S::StrId>,
iter: EncodedTuplesIterator,
variables: Rc<Vec<Variable>>,
) -> QuerySolutionIter {
let eval = self.clone();
@ -1840,7 +1816,7 @@ where
&self,
variables: Rc<Vec<Variable>>,
iter: QuerySolutionIter,
) -> EncodedTuplesIterator<S::StrId> {
) -> 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<S::StrId>, b: EncodedTerm<S::StrId>) -> Option<bool> {
fn equals(&self, a: EncodedTerm, b: EncodedTerm) -> Option<bool> {
match a {
EncodedTerm::DefaultGraph
| EncodedTerm::NamedNode { .. }
@ -2012,9 +1988,9 @@ where
fn cmp_according_to_expression(
&self,
tuple_a: &EncodedTuple<S::StrId>,
tuple_b: &EncodedTuple<S::StrId>,
expression: &PlanExpression<S::StrId>,
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<EncodedTerm<S::StrId>>,
b: Option<EncodedTerm<S::StrId>>,
) -> Ordering {
fn cmp_terms(&self, a: Option<EncodedTerm>, b: Option<EncodedTerm>) -> 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<S::StrId>,
b: EncodedTerm<S::StrId>,
) -> Option<Ordering> {
fn partial_cmp_literals(&self, a: EncodedTerm, b: EncodedTerm) -> Option<Ordering> {
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<Ordering> {
fn compare_str_ids(&self, a: StrHash, b: StrHash) -> Option<Ordering> {
Some(
self.dataset
.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))
}
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()))
}
fn hash<H: Digest>(
&self,
arg: &PlanExpression<S::StrId>,
tuple: &EncodedTuple<S::StrId>,
) -> Option<EncodedTerm<S::StrId>> {
fn hash<H: Digest>(&self, arg: &PlanExpression, tuple: &EncodedTuple) -> Option<EncodedTerm> {
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<S::StrId>) -> Option<EncodedTerm<S::StrId>> {
fn datatype(&self, value: EncodedTerm) -> Option<EncodedTerm> {
//TODO: optimize?
match value {
EncodedTerm::NamedNode { .. }
@ -2269,7 +2233,7 @@ enum NumericBinaryOperands {
impl NumericBinaryOperands {
#[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) {
(EncodedTerm::FloatLiteral(v1), EncodedTerm::FloatLiteral(v2)) => {
Some(NumericBinaryOperands::Float(v1, v2))
@ -2387,32 +2351,25 @@ impl NumericBinaryOperands {
}
}
fn get_pattern_value<I: StrId>(
selector: &PatternValue<I>,
tuple: &EncodedTuple<I>,
) -> Option<EncodedTerm<I>> {
fn get_pattern_value(selector: &PatternValue, tuple: &EncodedTuple) -> Option<EncodedTerm> {
match selector {
PatternValue::Constant(term) => Some(*term),
PatternValue::Variable(v) => tuple.get(*v),
}
}
fn put_pattern_value<I: StrId>(
selector: &PatternValue<I>,
value: EncodedTerm<I>,
tuple: &mut EncodedTuple<I>,
) {
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<I: StrId>(
fn put_variable_value(
selector: &Variable,
variables: &[Variable],
value: EncodedTerm<I>,
tuple: &mut EncodedTuple<I>,
value: EncodedTerm,
tuple: &mut EncodedTuple,
) {
for (i, v) in variables.iter().enumerate() {
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 {
binding.unset(*var)
}
}
fn combine_tuples<I: StrId>(
mut a: EncodedTuple<I>,
b: &EncodedTuple<I>,
vars: &[usize],
) -> Option<EncodedTuple<I>> {
fn combine_tuples(mut a: EncodedTuple, b: &EncodedTuple, vars: &[usize]) -> Option<EncodedTuple> {
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<I: StrId>(
Some(a)
}
pub fn are_compatible_and_not_disjointed<I: StrId>(
a: &EncodedTuple<I>,
b: &EncodedTuple<I>,
) -> 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<I: StrId>(
found_intersection
}
struct JoinIterator<I: StrId> {
left: Vec<EncodedTuple<I>>,
right_iter: EncodedTuplesIterator<I>,
buffered_results: Vec<Result<EncodedTuple<I>, EvaluationError>>,
struct JoinIterator {
left: Vec<EncodedTuple>,
right_iter: EncodedTuplesIterator,
buffered_results: Vec<Result<EncodedTuple, EvaluationError>>,
}
impl<I: StrId> Iterator for JoinIterator<I> {
type Item = Result<EncodedTuple<I>, EvaluationError>;
impl Iterator for JoinIterator {
type Item = Result<EncodedTuple, EvaluationError>;
fn next(&mut self) -> Option<Result<EncodedTuple<I>, EvaluationError>> {
fn next(&mut self) -> Option<Result<EncodedTuple, EvaluationError>> {
loop {
if let Some(result) = self.buffered_results.pop() {
return Some(result);
@ -2490,15 +2440,15 @@ impl<I: StrId> Iterator for JoinIterator<I> {
}
}
struct AntiJoinIterator<I: StrId> {
left_iter: EncodedTuplesIterator<I>,
right: Vec<EncodedTuple<I>>,
struct AntiJoinIterator {
left_iter: EncodedTuplesIterator,
right: Vec<EncodedTuple>,
}
impl<I: StrId> Iterator for AntiJoinIterator<I> {
type Item = Result<EncodedTuple<I>, EvaluationError>;
impl Iterator for AntiJoinIterator {
type Item = Result<EncodedTuple, EvaluationError>;
fn next(&mut self) -> Option<Result<EncodedTuple<I>, EvaluationError>> {
fn next(&mut self) -> Option<Result<EncodedTuple, EvaluationError>> {
loop {
match self.left_iter.next()? {
Ok(left_tuple) => {
@ -2517,18 +2467,18 @@ impl<I: StrId> Iterator for AntiJoinIterator<I> {
struct LeftJoinIterator<S: ReadableEncodedStore + 'static> {
eval: SimpleEvaluator<S>,
right_plan: Rc<PlanNode<S::StrId>>,
left_iter: EncodedTuplesIterator<S::StrId>,
current_right: EncodedTuplesIterator<S::StrId>,
right_plan: Rc<PlanNode>,
left_iter: EncodedTuplesIterator,
current_right: EncodedTuplesIterator,
}
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for LeftJoinIterator<S>
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() {
return Some(tuple);
}
@ -2548,20 +2498,20 @@ where
struct BadLeftJoinIterator<S: ReadableEncodedStore + 'static> {
eval: SimpleEvaluator<S>,
right_plan: Rc<PlanNode<S::StrId>>,
left_iter: EncodedTuplesIterator<S::StrId>,
current_left: Option<EncodedTuple<S::StrId>>,
current_right: EncodedTuplesIterator<S::StrId>,
right_plan: Rc<PlanNode>,
left_iter: EncodedTuplesIterator,
current_left: Option<EncodedTuple>,
current_right: EncodedTuplesIterator,
problem_vars: Rc<Vec<usize>>,
}
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for BadLeftJoinIterator<S>
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() {
match right_tuple {
Ok(right_tuple) => {
@ -2603,19 +2553,19 @@ where
struct UnionIterator<S: ReadableEncodedStore + 'static> {
eval: SimpleEvaluator<S>,
plans: Vec<Rc<PlanNode<S::StrId>>>,
input: EncodedTuple<S::StrId>,
current_iterator: EncodedTuplesIterator<S::StrId>,
plans: Vec<Rc<PlanNode>>,
input: EncodedTuple,
current_iterator: EncodedTuplesIterator,
current_plan: usize,
}
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for UnionIterator<S>
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 {
if let Some(tuple) = self.current_iterator.next() {
return Some(tuple);
@ -2633,10 +2583,10 @@ where
struct ConstructIterator<S: ReadableEncodedStore + 'static> {
eval: SimpleEvaluator<S>,
iter: EncodedTuplesIterator<S::StrId>,
template: Vec<TripleTemplate<S::StrId>>,
iter: EncodedTuplesIterator,
template: Vec<TripleTemplate>,
buffered_results: Vec<Result<Triple, EvaluationError>>,
bnodes: Vec<EncodedTerm<S::StrId>>,
bnodes: Vec<EncodedTerm>,
}
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>(
selector: &TripleTemplateValue<I>,
tuple: &EncodedTuple<I>,
bnodes: &mut Vec<EncodedTerm<I>>,
) -> Option<EncodedTerm<I>> {
fn get_triple_template_value(
selector: &TripleTemplateValue,
tuple: &EncodedTuple,
bnodes: &mut Vec<EncodedTerm>,
) -> Option<EncodedTerm> {
match selector {
TripleTemplateValue::Constant(term) => Some(*term),
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() }
}
fn decode_triple<D: Decoder>(
decoder: &D,
subject: EncodedTerm<D::StrId>,
predicate: EncodedTerm<D::StrId>,
object: EncodedTerm<D::StrId>,
subject: EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
) -> Result<Triple, EvaluationError> {
Ok(Triple::new(
decoder.decode_named_or_blank_node(subject)?,
@ -2708,8 +2658,8 @@ fn decode_triple<D: Decoder>(
struct DescribeIterator<S: ReadableEncodedStore + 'static> {
eval: SimpleEvaluator<S>,
iter: EncodedTuplesIterator<S::StrId>,
quads: Box<dyn Iterator<Item = Result<EncodedQuad<S::StrId>, EvaluationError>>>,
iter: EncodedTuplesIterator,
quads: Box<dyn Iterator<Item = Result<EncodedQuad, EvaluationError>>>,
}
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Iterator for DescribeIterator<S> {
@ -2894,19 +2844,19 @@ impl<
}
}
trait Accumulator<I: StrId> {
fn add(&mut self, element: Option<EncodedTerm<I>>);
trait Accumulator {
fn add(&mut self, element: Option<EncodedTerm>);
fn state(&self) -> Option<EncodedTerm<I>>;
fn state(&self) -> Option<EncodedTerm>;
}
#[derive(Default, Debug)]
struct DistinctAccumulator<I: StrId, T: Accumulator<I>> {
seen: HashSet<Option<EncodedTerm<I>>>,
struct DistinctAccumulator<T: Accumulator> {
seen: HashSet<Option<EncodedTerm>>,
inner: T,
}
impl<I: StrId, T: Accumulator<I>> DistinctAccumulator<I, T> {
impl<T: Accumulator> DistinctAccumulator<T> {
fn new(inner: T) -> Self {
Self {
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> {
fn add(&mut self, element: Option<EncodedTerm<I>>) {
impl<T: Accumulator> Accumulator for DistinctAccumulator<T> {
fn add(&mut self, element: Option<EncodedTerm>) {
if self.seen.insert(element) {
self.inner.add(element)
}
}
fn state(&self) -> Option<EncodedTerm<I>> {
fn state(&self) -> Option<EncodedTerm> {
self.inner.state()
}
}
@ -2932,22 +2882,22 @@ struct CountAccumulator {
count: i64,
}
impl<I: StrId> Accumulator<I> for CountAccumulator {
fn add(&mut self, _element: Option<EncodedTerm<I>>) {
impl Accumulator for CountAccumulator {
fn add(&mut self, _element: Option<EncodedTerm>) {
self.count += 1;
}
fn state(&self) -> Option<EncodedTerm<I>> {
fn state(&self) -> Option<EncodedTerm> {
Some(self.count.into())
}
}
#[derive(Debug)]
struct SumAccumulator<I: StrId> {
sum: Option<EncodedTerm<I>>,
struct SumAccumulator {
sum: Option<EncodedTerm>,
}
impl<I: StrId> Default for SumAccumulator<I> {
impl Default for SumAccumulator {
fn default() -> Self {
Self {
sum: Some(0.into()),
@ -2955,8 +2905,8 @@ impl<I: StrId> Default for SumAccumulator<I> {
}
}
impl<I: StrId> Accumulator<I> for SumAccumulator<I> {
fn add(&mut self, element: Option<EncodedTerm<I>>) {
impl Accumulator for SumAccumulator {
fn add(&mut self, element: Option<EncodedTerm>) {
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<I: StrId> Accumulator<I> for SumAccumulator<I> {
}
}
fn state(&self) -> Option<EncodedTerm<I>> {
fn state(&self) -> Option<EncodedTerm> {
self.sum
}
}
#[derive(Debug)]
struct AvgAccumulator<I: StrId> {
sum: SumAccumulator<I>,
struct AvgAccumulator {
sum: SumAccumulator,
count: CountAccumulator,
}
impl<I: StrId> Default for AvgAccumulator<I> {
impl Default for AvgAccumulator {
fn default() -> Self {
Self {
sum: SumAccumulator::default(),
@ -2994,13 +2944,13 @@ impl<I: StrId> Default for AvgAccumulator<I> {
}
}
impl<I: StrId> Accumulator<I> for AvgAccumulator<I> {
fn add(&mut self, element: Option<EncodedTerm<I>>) {
impl Accumulator for AvgAccumulator {
fn add(&mut self, element: Option<EncodedTerm>) {
self.sum.add(element);
self.count.add(element);
}
fn state(&self) -> Option<EncodedTerm<I>> {
fn state(&self) -> Option<EncodedTerm> {
let sum = self.sum.state()?;
let count = self.count.state()?;
if count == EncodedTerm::from(0) {
@ -3024,7 +2974,7 @@ impl<I: StrId> Accumulator<I> for AvgAccumulator<I> {
#[allow(clippy::option_option)]
struct MinAccumulator<S: ReadableEncodedStore + 'static> {
eval: SimpleEvaluator<S>,
min: Option<Option<EncodedTerm<S::StrId>>>,
min: Option<Option<EncodedTerm>>,
}
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>
for MinAccumulator<S>
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Accumulator for MinAccumulator<S>
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 self.eval.cmp_terms(element, min) == Ordering::Less {
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)
}
}
@ -3056,7 +3005,7 @@ where
#[allow(clippy::option_option)]
struct MaxAccumulator<S: ReadableEncodedStore + 'static> {
eval: SimpleEvaluator<S>,
max: Option<Option<EncodedTerm<S::StrId>>>,
max: Option<Option<EncodedTerm>>,
}
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>
for MaxAccumulator<S>
impl<S: ReadableEncodedStore<Error = EvaluationError> + 'static> Accumulator for MaxAccumulator<S>
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 self.eval.cmp_terms(element, max) == Ordering::Greater {
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)
}
}
#[derive(Debug)]
struct SampleAccumulator<I: StrId> {
value: Option<EncodedTerm<I>>,
struct SampleAccumulator {
value: Option<EncodedTerm>,
}
impl<I: StrId> Default for SampleAccumulator<I> {
impl Default for SampleAccumulator {
fn default() -> Self {
Self { value: None }
}
}
impl<I: StrId> Accumulator<I> for SampleAccumulator<I> {
fn add(&mut self, element: Option<EncodedTerm<I>>) {
impl Accumulator for SampleAccumulator {
fn add(&mut self, element: Option<EncodedTerm>) {
if element.is_some() {
self.value = element
}
}
fn state(&self) -> Option<EncodedTerm<I>> {
fn state(&self) -> Option<EncodedTerm> {
self.value
}
}
@ -3112,7 +3060,7 @@ impl<I: StrId> Accumulator<I> for SampleAccumulator<I> {
struct GroupConcatAccumulator<S: ReadableEncodedStore + 'static> {
eval: SimpleEvaluator<S>,
concat: Option<String>,
language: Option<Option<SmallStringOrId<S::StrId>>>,
language: Option<Option<SmallStringOrId>>,
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>
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(element) = 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.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<I: StrId> {
enum SmallStringOrId {
Small(SmallString),
Big(I),
Big(StrHash),
}
impl<I: StrId> From<SmallString> for SmallStringOrId<I> {
impl From<SmallString> for SmallStringOrId {
fn from(value: SmallString) -> Self {
Self::Small(value)
}
}
impl<I: StrId> From<I> for SmallStringOrId<I> {
fn from(value: I) -> Self {
impl From<StrHash> for SmallStringOrId {
fn from(value: StrHash) -> Self {
Self::Big(value)
}
}

@ -182,7 +182,7 @@ impl From<QueryOptions> for UpdateOptions {
pub(crate) fn evaluate_update<
R: ReadableEncodedStore + Clone + 'static,
W: StrContainer<StrId = R::StrId> + WritableEncodedStore<StrId = R::StrId>,
W: StrContainer + WritableEncodedStore,
>(
read: R,
write: &mut W,

@ -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<I: StrId> {
pub enum PlanNode {
Init,
StaticBindings {
tuples: Vec<EncodedTuple<I>>,
tuples: Vec<EncodedTuple>,
},
Service {
service_name: PatternValue<I>,
service_name: PatternValue,
variables: Rc<Vec<Variable>>,
child: Rc<PlanNode<I>>,
child: Rc<PlanNode>,
graph_pattern: Rc<GraphPattern>,
silent: bool,
},
QuadPatternJoin {
child: Rc<PlanNode<I>>,
subject: PatternValue<I>,
predicate: PatternValue<I>,
object: PatternValue<I>,
graph_name: PatternValue<I>,
child: Rc<PlanNode>,
subject: PatternValue,
predicate: PatternValue,
object: PatternValue,
graph_name: PatternValue,
},
PathPatternJoin {
child: Rc<PlanNode<I>>,
subject: PatternValue<I>,
path: Rc<PlanPropertyPath<I>>,
object: PatternValue<I>,
graph_name: PatternValue<I>,
child: Rc<PlanNode>,
subject: PatternValue,
path: Rc<PlanPropertyPath>,
object: PatternValue,
graph_name: PatternValue,
},
Join {
left: Rc<PlanNode<I>>,
right: Rc<PlanNode<I>>,
left: Rc<PlanNode>,
right: Rc<PlanNode>,
},
AntiJoin {
left: Rc<PlanNode<I>>,
right: Rc<PlanNode<I>>,
left: Rc<PlanNode>,
right: Rc<PlanNode>,
},
Filter {
child: Rc<PlanNode<I>>,
expression: Rc<PlanExpression<I>>,
child: Rc<PlanNode>,
expression: Rc<PlanExpression>,
},
Union {
children: Vec<Rc<PlanNode<I>>>,
children: Vec<Rc<PlanNode>>,
},
LeftJoin {
left: Rc<PlanNode<I>>,
right: Rc<PlanNode<I>>,
left: Rc<PlanNode>,
right: Rc<PlanNode>,
possible_problem_vars: Rc<Vec<usize>>, //Variables that should not be part of the entry of the left join
},
Extend {
child: Rc<PlanNode<I>>,
child: Rc<PlanNode>,
position: usize,
expression: Rc<PlanExpression<I>>,
expression: Rc<PlanExpression>,
},
Sort {
child: Rc<PlanNode<I>>,
by: Vec<Comparator<I>>,
child: Rc<PlanNode>,
by: Vec<Comparator>,
},
HashDeduplicate {
child: Rc<PlanNode<I>>,
child: Rc<PlanNode>,
},
Skip {
child: Rc<PlanNode<I>>,
child: Rc<PlanNode>,
count: usize,
},
Limit {
child: Rc<PlanNode<I>>,
child: Rc<PlanNode>,
count: usize,
},
Project {
child: Rc<PlanNode<I>>,
child: Rc<PlanNode>,
mapping: Rc<Vec<(usize, usize)>>, // 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<PlanNode<I>>,
child: Rc<PlanNode>,
key_mapping: Rc<Vec<(usize, usize)>>, // aggregate key pairs of (variable key in child, variable key in output)
aggregates: Rc<Vec<(PlanAggregation<I>, usize)>>,
aggregates: Rc<Vec<(PlanAggregation, usize)>>,
},
}
impl<I: StrId> PlanNode<I> {
impl PlanNode {
/// Returns variables that might be bound in the result set
pub fn maybe_bound_variables(&self) -> BTreeSet<usize> {
let mut set = BTreeSet::default();
@ -194,12 +194,12 @@ impl<I: StrId> PlanNode<I> {
}
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
pub enum PatternValue<I: StrId> {
Constant(EncodedTerm<I>),
pub enum PatternValue {
Constant(EncodedTerm),
Variable(usize),
}
impl<I: StrId> PatternValue<I> {
impl PatternValue {
pub fn is_var(&self) -> bool {
match self {
PatternValue::Constant(_) => false,
@ -209,107 +209,107 @@ impl<I: StrId> PatternValue<I> {
}
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub enum PlanExpression<I: StrId> {
Constant(EncodedTerm<I>),
pub enum PlanExpression {
Constant(EncodedTerm),
Variable(usize),
Exists(Rc<PlanNode<I>>),
Or(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
And(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
Equal(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
Greater(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
GreaterOrEqual(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
Less(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
LessOrEqual(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
In(Box<PlanExpression<I>>, Vec<PlanExpression<I>>),
Add(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
Subtract(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
Multiply(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
Divide(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
UnaryPlus(Box<PlanExpression<I>>),
UnaryMinus(Box<PlanExpression<I>>),
Not(Box<PlanExpression<I>>),
Str(Box<PlanExpression<I>>),
Lang(Box<PlanExpression<I>>),
LangMatches(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
Datatype(Box<PlanExpression<I>>),
Exists(Rc<PlanNode>),
Or(Box<PlanExpression>, Box<PlanExpression>),
And(Box<PlanExpression>, Box<PlanExpression>),
Equal(Box<PlanExpression>, Box<PlanExpression>),
Greater(Box<PlanExpression>, Box<PlanExpression>),
GreaterOrEqual(Box<PlanExpression>, Box<PlanExpression>),
Less(Box<PlanExpression>, Box<PlanExpression>),
LessOrEqual(Box<PlanExpression>, Box<PlanExpression>),
In(Box<PlanExpression>, Vec<PlanExpression>),
Add(Box<PlanExpression>, Box<PlanExpression>),
Subtract(Box<PlanExpression>, Box<PlanExpression>),
Multiply(Box<PlanExpression>, Box<PlanExpression>),
Divide(Box<PlanExpression>, Box<PlanExpression>),
UnaryPlus(Box<PlanExpression>),
UnaryMinus(Box<PlanExpression>),
Not(Box<PlanExpression>),
Str(Box<PlanExpression>),
Lang(Box<PlanExpression>),
LangMatches(Box<PlanExpression>, Box<PlanExpression>),
Datatype(Box<PlanExpression>),
Bound(usize),
Iri(Box<PlanExpression<I>>),
BNode(Option<Box<PlanExpression<I>>>),
Iri(Box<PlanExpression>),
BNode(Option<Box<PlanExpression>>),
Rand,
Abs(Box<PlanExpression<I>>),
Ceil(Box<PlanExpression<I>>),
Floor(Box<PlanExpression<I>>),
Round(Box<PlanExpression<I>>),
Concat(Vec<PlanExpression<I>>),
Abs(Box<PlanExpression>),
Ceil(Box<PlanExpression>),
Floor(Box<PlanExpression>),
Round(Box<PlanExpression>),
Concat(Vec<PlanExpression>),
SubStr(
Box<PlanExpression<I>>,
Box<PlanExpression<I>>,
Option<Box<PlanExpression<I>>>,
Box<PlanExpression>,
Box<PlanExpression>,
Option<Box<PlanExpression>>,
),
StrLen(Box<PlanExpression<I>>),
StrLen(Box<PlanExpression>),
Replace(
Box<PlanExpression<I>>,
Box<PlanExpression<I>>,
Box<PlanExpression<I>>,
Option<Box<PlanExpression<I>>>,
Box<PlanExpression>,
Box<PlanExpression>,
Box<PlanExpression>,
Option<Box<PlanExpression>>,
),
UCase(Box<PlanExpression<I>>),
LCase(Box<PlanExpression<I>>),
EncodeForUri(Box<PlanExpression<I>>),
Contains(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
StrStarts(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
StrEnds(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
StrBefore(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
StrAfter(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
Year(Box<PlanExpression<I>>),
Month(Box<PlanExpression<I>>),
Day(Box<PlanExpression<I>>),
Hours(Box<PlanExpression<I>>),
Minutes(Box<PlanExpression<I>>),
Seconds(Box<PlanExpression<I>>),
Timezone(Box<PlanExpression<I>>),
Tz(Box<PlanExpression<I>>),
UCase(Box<PlanExpression>),
LCase(Box<PlanExpression>),
EncodeForUri(Box<PlanExpression>),
Contains(Box<PlanExpression>, Box<PlanExpression>),
StrStarts(Box<PlanExpression>, Box<PlanExpression>),
StrEnds(Box<PlanExpression>, Box<PlanExpression>),
StrBefore(Box<PlanExpression>, Box<PlanExpression>),
StrAfter(Box<PlanExpression>, Box<PlanExpression>),
Year(Box<PlanExpression>),
Month(Box<PlanExpression>),
Day(Box<PlanExpression>),
Hours(Box<PlanExpression>),
Minutes(Box<PlanExpression>),
Seconds(Box<PlanExpression>),
Timezone(Box<PlanExpression>),
Tz(Box<PlanExpression>),
Now,
Uuid,
StrUuid,
Md5(Box<PlanExpression<I>>),
Sha1(Box<PlanExpression<I>>),
Sha256(Box<PlanExpression<I>>),
Sha384(Box<PlanExpression<I>>),
Sha512(Box<PlanExpression<I>>),
Coalesce(Vec<PlanExpression<I>>),
Md5(Box<PlanExpression>),
Sha1(Box<PlanExpression>),
Sha256(Box<PlanExpression>),
Sha384(Box<PlanExpression>),
Sha512(Box<PlanExpression>),
Coalesce(Vec<PlanExpression>),
If(
Box<PlanExpression<I>>,
Box<PlanExpression<I>>,
Box<PlanExpression<I>>,
Box<PlanExpression>,
Box<PlanExpression>,
Box<PlanExpression>,
),
StrLang(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
StrDt(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
SameTerm(Box<PlanExpression<I>>, Box<PlanExpression<I>>),
IsIri(Box<PlanExpression<I>>),
IsBlank(Box<PlanExpression<I>>),
IsLiteral(Box<PlanExpression<I>>),
IsNumeric(Box<PlanExpression<I>>),
StrLang(Box<PlanExpression>, Box<PlanExpression>),
StrDt(Box<PlanExpression>, Box<PlanExpression>),
SameTerm(Box<PlanExpression>, Box<PlanExpression>),
IsIri(Box<PlanExpression>),
IsBlank(Box<PlanExpression>),
IsLiteral(Box<PlanExpression>),
IsNumeric(Box<PlanExpression>),
Regex(
Box<PlanExpression<I>>,
Box<PlanExpression<I>>,
Option<Box<PlanExpression<I>>>,
Box<PlanExpression>,
Box<PlanExpression>,
Option<Box<PlanExpression>>,
),
BooleanCast(Box<PlanExpression<I>>),
DoubleCast(Box<PlanExpression<I>>),
FloatCast(Box<PlanExpression<I>>),
DecimalCast(Box<PlanExpression<I>>),
IntegerCast(Box<PlanExpression<I>>),
DateCast(Box<PlanExpression<I>>),
TimeCast(Box<PlanExpression<I>>),
DateTimeCast(Box<PlanExpression<I>>),
DurationCast(Box<PlanExpression<I>>),
YearMonthDurationCast(Box<PlanExpression<I>>),
DayTimeDurationCast(Box<PlanExpression<I>>),
StringCast(Box<PlanExpression<I>>),
BooleanCast(Box<PlanExpression>),
DoubleCast(Box<PlanExpression>),
FloatCast(Box<PlanExpression>),
DecimalCast(Box<PlanExpression>),
IntegerCast(Box<PlanExpression>),
DateCast(Box<PlanExpression>),
TimeCast(Box<PlanExpression>),
DateTimeCast(Box<PlanExpression>),
DurationCast(Box<PlanExpression>),
YearMonthDurationCast(Box<PlanExpression>),
DayTimeDurationCast(Box<PlanExpression>),
StringCast(Box<PlanExpression>),
}
impl<I: StrId> PlanExpression<I> {
impl PlanExpression {
pub fn add_maybe_bound_variables(&self, set: &mut BTreeSet<usize>) {
match self {
PlanExpression::Variable(v) | PlanExpression::Bound(v) => {
@ -425,9 +425,9 @@ impl<I: StrId> PlanExpression<I> {
}
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct PlanAggregation<I: StrId> {
pub struct PlanAggregation {
pub function: PlanAggregationFunction,
pub parameter: Option<PlanExpression<I>>,
pub parameter: Option<PlanExpression>,
pub distinct: bool,
}
@ -443,43 +443,43 @@ pub enum PlanAggregationFunction {
}
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub enum PlanPropertyPath<I: StrId> {
Path(EncodedTerm<I>),
Reverse(Rc<PlanPropertyPath<I>>),
Sequence(Rc<PlanPropertyPath<I>>, Rc<PlanPropertyPath<I>>),
Alternative(Rc<PlanPropertyPath<I>>, Rc<PlanPropertyPath<I>>),
ZeroOrMore(Rc<PlanPropertyPath<I>>),
OneOrMore(Rc<PlanPropertyPath<I>>),
ZeroOrOne(Rc<PlanPropertyPath<I>>),
NegatedPropertySet(Rc<Vec<EncodedTerm<I>>>),
pub enum PlanPropertyPath {
Path(EncodedTerm),
Reverse(Rc<PlanPropertyPath>),
Sequence(Rc<PlanPropertyPath>, Rc<PlanPropertyPath>),
Alternative(Rc<PlanPropertyPath>, Rc<PlanPropertyPath>),
ZeroOrMore(Rc<PlanPropertyPath>),
OneOrMore(Rc<PlanPropertyPath>),
ZeroOrOne(Rc<PlanPropertyPath>),
NegatedPropertySet(Rc<Vec<EncodedTerm>>),
}
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub enum Comparator<I: StrId> {
Asc(PlanExpression<I>),
Desc(PlanExpression<I>),
pub enum Comparator {
Asc(PlanExpression),
Desc(PlanExpression),
}
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
pub struct TripleTemplate<I: StrId> {
pub subject: TripleTemplateValue<I>,
pub predicate: TripleTemplateValue<I>,
pub object: TripleTemplateValue<I>,
pub struct TripleTemplate {
pub subject: TripleTemplateValue,
pub predicate: TripleTemplateValue,
pub object: TripleTemplateValue,
}
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
pub enum TripleTemplateValue<I: StrId> {
Constant(EncodedTerm<I>),
pub enum TripleTemplateValue {
Constant(EncodedTerm),
BlankNode(usize),
Variable(usize),
}
#[derive(Eq, PartialEq, Debug, Clone, Hash)]
pub struct EncodedTuple<I: StrId> {
inner: Vec<Option<EncodedTerm<I>>>,
pub struct EncodedTuple {
inner: Vec<Option<EncodedTerm>>,
}
impl<I: StrId> EncodedTuple<I> {
impl EncodedTuple {
pub fn with_capacity(capacity: usize) -> Self {
Self {
inner: Vec::with_capacity(capacity),
@ -494,15 +494,15 @@ impl<I: StrId> EncodedTuple<I> {
self.inner.get(index).map_or(false, Option::is_some)
}
pub fn get(&self, index: usize) -> Option<EncodedTerm<I>> {
pub fn get(&self, index: usize) -> Option<EncodedTerm> {
self.inner.get(index).cloned().unwrap_or(None)
}
pub fn iter(&self) -> impl Iterator<Item = Option<EncodedTerm<I>>> + '_ {
pub fn iter(&self) -> impl Iterator<Item = Option<EncodedTerm>> + '_ {
self.inner.iter().cloned()
}
pub fn set(&mut self, index: usize, value: EncodedTerm<I>) {
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<I: StrId> EncodedTuple<I> {
}
}
pub fn combine_with(&self, other: &EncodedTuple<I>) -> Option<Self> {
pub fn combine_with(&self, other: &EncodedTuple) -> Option<Self> {
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<I: StrId> EncodedTuple<I> {
}
}
impl<I: StrId> IntoIterator for EncodedTuple<I> {
type Item = Option<EncodedTerm<I>>;
type IntoIter = std::vec::IntoIter<Option<EncodedTerm<I>>>;
impl IntoIterator for EncodedTuple {
type Item = Option<EncodedTerm>;
type IntoIter = std::vec::IntoIter<Option<EncodedTerm>>;
fn into_iter(self) -> Self::IntoIter {
self.inner.into_iter()

@ -15,7 +15,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
pub fn build(
encoder: E,
pattern: &GraphPattern,
) -> Result<(PlanNode<E::StrId>, Vec<Variable>), EvaluationError> {
) -> Result<(PlanNode, Vec<Variable>), EvaluationError> {
let mut variables = Vec::default();
let plan = PlanBuilder { encoder }.build_for_graph_pattern(
pattern,
@ -29,7 +29,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
encoder: E,
template: &[TriplePattern],
mut variables: Vec<Variable>,
) -> Result<Vec<TripleTemplate<E::StrId>>, EvaluationError> {
) -> Result<Vec<TripleTemplate>, EvaluationError> {
PlanBuilder { encoder }.build_for_graph_template(template, &mut variables)
}
@ -37,8 +37,8 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
&mut self,
pattern: &GraphPattern,
variables: &mut Vec<Variable>,
graph_name: PatternValue<E::StrId>,
) -> Result<PlanNode<E::StrId>, EvaluationError> {
graph_name: PatternValue,
) -> Result<PlanNode, EvaluationError> {
Ok(match pattern {
GraphPattern::BGP(p) => self.build_for_bgp(p, variables, graph_name)?,
GraphPattern::Path {
@ -268,8 +268,8 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
&mut self,
p: &[TriplePattern],
variables: &mut Vec<Variable>,
graph_name: PatternValue<E::StrId>,
) -> Result<PlanNode<E::StrId>, EvaluationError> {
graph_name: PatternValue,
) -> Result<PlanNode, EvaluationError> {
let mut plan = PlanNode::Init;
for pattern in sort_bgp(p) {
plan = PlanNode::QuadPatternJoin {
@ -287,7 +287,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
fn build_for_path(
&mut self,
path: &PropertyPathExpression,
) -> Result<PlanPropertyPath<E::StrId>, EvaluationError> {
) -> Result<PlanPropertyPath, EvaluationError> {
Ok(match path {
PropertyPathExpression::NamedNode(p) => {
PlanPropertyPath::Path(self.build_named_node(p)?)
@ -326,8 +326,8 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
&mut self,
expression: &Expression,
variables: &mut Vec<Variable>,
graph_name: PatternValue<E::StrId>,
) -> Result<PlanExpression<E::StrId>, EvaluationError> {
graph_name: PatternValue,
) -> Result<PlanExpression, EvaluationError> {
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<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
fn build_cast(
&mut self,
parameters: &[Expression],
constructor: impl Fn(Box<PlanExpression<E::StrId>>) -> PlanExpression<E::StrId>,
constructor: impl Fn(Box<PlanExpression>) -> PlanExpression,
variables: &mut Vec<Variable>,
graph_name: PatternValue<E::StrId>,
graph_name: PatternValue,
name: &'static str,
) -> Result<PlanExpression<E::StrId>, EvaluationError> {
) -> Result<PlanExpression, EvaluationError> {
if parameters.len() == 1 {
Ok(constructor(Box::new(self.build_for_expression(
&parameters[0],
@ -751,8 +751,8 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
&mut self,
l: &[Expression],
variables: &mut Vec<Variable>,
graph_name: PatternValue<E::StrId>,
) -> Result<Vec<PlanExpression<E::StrId>>, EvaluationError> {
graph_name: PatternValue,
) -> Result<Vec<PlanExpression>, EvaluationError> {
l.iter()
.map(|e| self.build_for_expression(e, variables, graph_name))
.collect()
@ -762,7 +762,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
&mut self,
term_or_variable: &TermOrVariable,
variables: &mut Vec<Variable>,
) -> Result<PatternValue<E::StrId>, EvaluationError> {
) -> Result<PatternValue, EvaluationError> {
Ok(match term_or_variable {
TermOrVariable::Variable(variable) => {
PatternValue::Variable(variable_key(variables, variable))
@ -782,7 +782,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
&mut self,
named_node_or_variable: &NamedNodeOrVariable,
variables: &mut Vec<Variable>,
) -> Result<PatternValue<E::StrId>, EvaluationError> {
) -> Result<PatternValue, EvaluationError> {
Ok(match named_node_or_variable {
NamedNodeOrVariable::NamedNode(named_node) => {
PatternValue::Constant(self.build_named_node(named_node)?)
@ -798,7 +798,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
table_variables: &[Variable],
rows: &[Vec<Option<Term>>],
variables: &mut Vec<Variable>,
) -> Result<Vec<EncodedTuple<E::StrId>>, EvaluationError> {
) -> Result<Vec<EncodedTuple>, EvaluationError> {
let bindings_variables_keys = table_variables
.iter()
.map(|v| variable_key(variables, v))
@ -820,8 +820,8 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
&mut self,
aggregate: &AggregationFunction,
variables: &mut Vec<Variable>,
graph_name: PatternValue<E::StrId>,
) -> Result<PlanAggregation<E::StrId>, EvaluationError> {
graph_name: PatternValue,
) -> Result<PlanAggregation, EvaluationError> {
match aggregate {
AggregationFunction::Count { expr, distinct } => Ok(PlanAggregation {
function: PlanAggregationFunction::Count,
@ -877,7 +877,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
&mut self,
template: &[TriplePattern],
variables: &mut Vec<Variable>,
) -> Result<Vec<TripleTemplate<E::StrId>>, EvaluationError> {
) -> Result<Vec<TripleTemplate>, EvaluationError> {
let mut bnodes = Vec::default();
template
.iter()
@ -905,7 +905,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
term_or_variable: &TermOrVariable,
variables: &mut Vec<Variable>,
bnodes: &mut Vec<BlankNode>,
) -> Result<TripleTemplateValue<E::StrId>, EvaluationError> {
) -> Result<TripleTemplateValue, EvaluationError> {
Ok(match term_or_variable {
TermOrVariable::Variable(variable) => {
TripleTemplateValue::Variable(variable_key(variables, variable))
@ -921,7 +921,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
&mut self,
named_node_or_variable: &NamedNodeOrVariable,
variables: &mut Vec<Variable>,
) -> Result<TripleTemplateValue<E::StrId>, EvaluationError> {
) -> Result<TripleTemplateValue, EvaluationError> {
Ok(match named_node_or_variable {
NamedNodeOrVariable::Variable(variable) => {
TripleTemplateValue::Variable(variable_key(variables, variable))
@ -934,10 +934,10 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
fn convert_pattern_value_id(
&self,
from_value: PatternValue<E::StrId>,
from_value: PatternValue,
from: &[Variable],
to: &mut Vec<Variable>,
) -> PatternValue<E::StrId> {
) -> PatternValue {
match from_value {
PatternValue::Constant(v) => PatternValue::Constant(v),
PatternValue::Variable(from_id) => {
@ -966,11 +966,7 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
}
}
fn add_left_join_problematic_variables(
&self,
node: &PlanNode<E::StrId>,
set: &mut BTreeSet<usize>,
) {
fn add_left_join_problematic_variables(&self, node: &PlanNode, set: &mut BTreeSet<usize>) {
match node {
PlanNode::Init
| PlanNode::StaticBindings { .. }
@ -1033,21 +1029,15 @@ impl<E: WriteEncoder<Error = EvaluationError>> PlanBuilder<E> {
}
}
fn build_named_node(
&mut self,
node: &NamedNode,
) -> Result<EncodedTerm<E::StrId>, EvaluationError> {
fn build_named_node(&mut self, node: &NamedNode) -> Result<EncodedTerm, EvaluationError> {
self.encoder.encode_named_node(node.as_ref())
}
fn build_literal(
&mut self,
literal: &Literal,
) -> Result<EncodedTerm<E::StrId>, EvaluationError> {
fn build_literal(&mut self, literal: &Literal) -> Result<EncodedTerm, EvaluationError> {
self.encoder.encode_literal(literal.as_ref())
}
fn build_term(&mut self, term: &Term) -> Result<EncodedTerm<E::StrId>, EvaluationError> {
fn build_term(&mut self, term: &Term) -> Result<EncodedTerm, EvaluationError> {
self.encoder.encode_term(term.as_ref())
}
}

@ -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<StrId = R::StrId> + WritableEncodedStore<StrId = R::StrId> + 'a,
W: StrContainer + WritableEncodedStore + 'a,
> SimpleUpdateEvaluator<'a, R, W>
where
io::Error: From<StoreOrParseError<W::Error>>,
@ -127,11 +127,7 @@ 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 {
t.on_each_id(|id| {
self.write
.insert_str(
&dataset
@ -144,11 +140,10 @@ where
})
.map_err(to_eval_error)?,
)
.map(|_| ())
.map_err(to_eval_error)
}
})
.map_err(to_eval_error)?,
)
})?;
Some(t)
} else {
None
})
@ -356,7 +351,7 @@ where
&mut self,
quad: &Quad,
bnodes: &mut HashMap<BlankNode, BlankNode>,
) -> Result<Option<EncodedQuad<R::StrId>>, EvaluationError> {
) -> Result<Option<EncodedQuad>, EvaluationError> {
Ok(Some(EncodedQuad {
subject: match &quad.subject {
NamedOrBlankNode::NamedNode(subject) => {
@ -390,9 +385,9 @@ where
&mut self,
quad: &QuadPattern,
variables: &[Variable],
values: &[Option<EncodedTerm<R::StrId>>],
values: &[Option<EncodedTerm>],
bnodes: &mut HashMap<BlankNode, BlankNode>,
) -> Result<Option<EncodedQuad<R::StrId>>, EvaluationError> {
) -> Result<Option<EncodedQuad>, 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<EncodedTerm<R::StrId>>],
values: &[Option<EncodedTerm>],
bnodes: &mut HashMap<BlankNode, BlankNode>,
validate: impl FnOnce(&EncodedTerm<R::StrId>) -> bool,
) -> Result<Option<EncodedTerm<R::StrId>>, EvaluationError> {
validate: impl FnOnce(&EncodedTerm) -> bool,
) -> Result<Option<EncodedTerm>, EvaluationError> {
Ok(match term {
TermOrVariable::Term(term) => Some(
self.write
@ -471,8 +466,8 @@ where
&mut self,
term: &NamedNodeOrVariable,
variables: &[Variable],
values: &[Option<EncodedTerm<R::StrId>>],
) -> Result<Option<EncodedTerm<R::StrId>>, EvaluationError> {
values: &[Option<EncodedTerm>],
) -> Result<Option<EncodedTerm>, 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<Option<EncodedQuad<R::StrId>>, EvaluationError> {
) -> Result<Option<EncodedQuad>, EvaluationError> {
Ok(Some(EncodedQuad {
subject: if let Some(subject) = self
.read
@ -545,8 +540,8 @@ where
&self,
quad: &QuadPattern,
variables: &[Variable],
values: &[Option<EncodedTerm<R::StrId>>],
) -> Result<Option<EncodedQuad<R::StrId>>, EvaluationError> {
values: &[Option<EncodedTerm>],
) -> Result<Option<EncodedQuad>, 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<EncodedTerm<R::StrId>>],
) -> Result<Option<EncodedTerm<R::StrId>>, EvaluationError> {
values: &[Option<EncodedTerm>],
) -> Result<Option<EncodedTerm>, EvaluationError> {
match term {
TermOrVariable::Term(term) => {
if term.is_blank_node() {
@ -619,8 +614,8 @@ where
&self,
term: &NamedNodeOrVariable,
variables: &[Variable],
values: &[Option<EncodedTerm<R::StrId>>],
) -> Result<Option<EncodedTerm<R::StrId>>, EvaluationError> {
values: &[Option<EncodedTerm>],
) -> Result<Option<EncodedTerm>, EvaluationError> {
Ok(match term {
NamedNodeOrVariable::NamedNode(term) => self
.read

@ -6,8 +6,8 @@ use std::io;
use std::io::{Cursor, Read};
use std::mem::size_of;
type EncodedTerm = crate::store::numeric_encoder::EncodedTerm<StrHash>;
type EncodedQuad = crate::store::numeric_encoder::EncodedQuad<StrHash>;
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::<u8>() + 2 * size_of::<StrHash>();
@ -648,7 +648,6 @@ mod tests {
impl StrEncodingAware for MemoryStrStore {
type Error = Infallible;
type StrId = StrHash;
}
impl StrLookup for MemoryStrStore {

@ -24,44 +24,32 @@ use std::io::{BufRead, Write};
use std::iter::Iterator;
pub(crate) trait ReadableEncodedStore: StrLookup {
type QuadsIter: Iterator<Item = Result<EncodedQuad<Self::StrId>, Self::Error>> + 'static;
type GraphsIter: Iterator<Item = Result<EncodedTerm<Self::StrId>, Self::Error>> + 'static;
type QuadsIter: Iterator<Item = Result<EncodedQuad, Self::Error>> + 'static;
type GraphsIter: Iterator<Item = Result<EncodedTerm, Self::Error>> + 'static;
fn encoded_quads_for_pattern(
&self,
subject: Option<EncodedTerm<Self::StrId>>,
predicate: Option<EncodedTerm<Self::StrId>>,
object: Option<EncodedTerm<Self::StrId>>,
graph_name: Option<EncodedTerm<Self::StrId>>,
subject: Option<EncodedTerm>,
predicate: Option<EncodedTerm>,
object: Option<EncodedTerm>,
graph_name: Option<EncodedTerm>,
) -> Self::QuadsIter;
fn encoded_named_graphs(&self) -> Self::GraphsIter;
fn contains_encoded_named_graph(
&self,
graph_name: EncodedTerm<Self::StrId>,
) -> Result<bool, Self::Error>;
fn contains_encoded_named_graph(&self, graph_name: EncodedTerm) -> Result<bool, Self::Error>;
}
pub(crate) trait WritableEncodedStore: StrEncodingAware {
fn insert_encoded(&mut self, quad: &EncodedQuad<Self::StrId>) -> Result<(), Self::Error>;
fn insert_encoded(&mut self, quad: &EncodedQuad) -> Result<(), Self::Error>;
fn remove_encoded(&mut self, quad: &EncodedQuad<Self::StrId>) -> Result<(), Self::Error>;
fn remove_encoded(&mut self, quad: &EncodedQuad) -> Result<(), Self::Error>;
fn insert_encoded_named_graph(
&mut self,
graph_name: EncodedTerm<Self::StrId>,
) -> 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<Self::StrId>,
) -> 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<Self::StrId>,
) -> 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<StoreOrParseError<Infallible>> for io::Error {
}
}
type QuadPattern<I> = (
Option<EncodedTerm<I>>,
Option<EncodedTerm<I>>,
Option<EncodedTerm<I>>,
Option<EncodedTerm<I>>,
type QuadPattern = (
Option<EncodedTerm>,
Option<EncodedTerm>,
Option<EncodedTerm>,
Option<EncodedTerm>,
);
fn get_encoded_quad_pattern<E: ReadEncoder>(
@ -228,7 +216,7 @@ fn get_encoded_quad_pattern<E: ReadEncoder>(
predicate: Option<NamedNodeRef<'_>>,
object: Option<TermRef<'_>>,
graph_name: Option<GraphNameRef<'_>>,
) -> Result<Option<QuadPattern<E::StrId>>, E::Error> {
) -> Result<Option<QuadPattern>, E::Error> {
Ok(Some((
if let Some(subject) = transpose(
subject

@ -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<I: StrId> {
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<I: StrId> {
},
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<I: StrId> {
DayTimeDurationLiteral(DayTimeDuration),
}
impl<I: StrId> PartialEq for EncodedTerm<I> {
impl PartialEq for EncodedTerm {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::DefaultGraph, Self::DefaultGraph) => true,
@ -223,9 +219,9 @@ impl<I: StrId> PartialEq for EncodedTerm<I> {
}
}
impl<I: StrId> Eq for EncodedTerm<I> {}
impl Eq for EncodedTerm {}
impl<I: StrId> Hash for EncodedTerm<I> {
impl Hash for EncodedTerm {
fn hash<H: Hasher>(&self, state: &mut H) {
match self {
Self::NamedNode { iri_id } => iri_id.hash(state),
@ -285,7 +281,7 @@ impl<I: StrId> Hash for EncodedTerm<I> {
}
}
impl<I: StrId> EncodedTerm<I> {
impl EncodedTerm {
pub fn is_named_node(&self) -> bool {
matches!(self, Self::NamedNode { .. })
}
@ -340,241 +336,146 @@ impl<I: StrId> EncodedTerm<I> {
matches!(self, Self::DefaultGraph)
}
pub fn map_id<J: StrId>(self, mapping: impl Fn(I) -> J) -> EncodedTerm<J> {
pub fn on_each_id<E>(
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::BigStringLiteral { value_id } => {
callback(value_id)?;
}
Self::BigSmallLangStringLiteral { value_id, language } => {
EncodedTerm::BigSmallLangStringLiteral {
value_id: mapping(value_id),
language,
Self::SmallBigLangStringLiteral { language_id, .. } => {
callback(language_id)?;
}
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),
},
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<J: StrId, E>(
self,
mut mapping: impl FnMut(I) -> Result<J, E>,
) -> Result<EncodedTerm<J>, 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 { value, language_id } => {
EncodedTerm::SmallBigLangStringLiteral {
value,
language_id: mapping(language_id)?,
}
}
Self::BigSmallLangStringLiteral { value_id, language } => {
EncodedTerm::BigSmallLangStringLiteral {
value_id: mapping(value_id)?,
language,
} => {
callback(value_id)?;
callback(language_id)?;
}
Self::SmallTypedLiteral { datatype_id, .. } => {
callback(datatype_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),
})
} => {
callback(value_id)?;
callback(datatype_id)?;
}
_ => (),
}
Ok(())
}
}
impl<I: StrId> From<bool> for EncodedTerm<I> {
impl From<bool> for EncodedTerm {
fn from(value: bool) -> Self {
Self::BooleanLiteral(value)
}
}
impl<I: StrId> From<i64> for EncodedTerm<I> {
impl From<i64> for EncodedTerm {
fn from(value: i64) -> Self {
Self::IntegerLiteral(value)
}
}
impl<I: StrId> From<i32> for EncodedTerm<I> {
impl From<i32> for EncodedTerm {
fn from(value: i32) -> Self {
Self::IntegerLiteral(value.into())
}
}
impl<I: StrId> From<u32> for EncodedTerm<I> {
impl From<u32> for EncodedTerm {
fn from(value: u32) -> Self {
Self::IntegerLiteral(value.into())
}
}
impl<I: StrId> From<u8> for EncodedTerm<I> {
impl From<u8> for EncodedTerm {
fn from(value: u8) -> Self {
Self::IntegerLiteral(value.into())
}
}
impl<I: StrId> From<f32> for EncodedTerm<I> {
impl From<f32> for EncodedTerm {
fn from(value: f32) -> Self {
Self::FloatLiteral(value)
}
}
impl<I: StrId> From<f64> for EncodedTerm<I> {
impl From<f64> for EncodedTerm {
fn from(value: f64) -> Self {
Self::DoubleLiteral(value)
}
}
impl<I: StrId> From<Decimal> for EncodedTerm<I> {
impl From<Decimal> for EncodedTerm {
fn from(value: Decimal) -> Self {
Self::DecimalLiteral(value)
}
}
impl<I: StrId> From<DateTime> for EncodedTerm<I> {
impl From<DateTime> for EncodedTerm {
fn from(value: DateTime) -> Self {
Self::DateTimeLiteral(value)
}
}
impl<I: StrId> From<Time> for EncodedTerm<I> {
impl From<Time> for EncodedTerm {
fn from(value: Time) -> Self {
Self::TimeLiteral(value)
}
}
impl<I: StrId> From<Date> for EncodedTerm<I> {
impl From<Date> for EncodedTerm {
fn from(value: Date) -> Self {
Self::DateLiteral(value)
}
}
impl<I: StrId> From<Duration> for EncodedTerm<I> {
impl From<Duration> for EncodedTerm {
fn from(value: Duration) -> Self {
Self::DurationLiteral(value)
}
}
impl<I: StrId> From<YearMonthDuration> for EncodedTerm<I> {
impl From<YearMonthDuration> for EncodedTerm {
fn from(value: YearMonthDuration) -> Self {
Self::YearMonthDurationLiteral(value)
}
}
impl<I: StrId> From<DayTimeDuration> for EncodedTerm<I> {
impl From<DayTimeDuration> for EncodedTerm {
fn from(value: DayTimeDuration) -> Self {
Self::DayTimeDurationLiteral(value)
}
}
#[derive(Eq, PartialEq, Debug, Clone, Copy, Hash)]
pub struct EncodedQuad<I: StrId> {
pub subject: EncodedTerm<I>,
pub predicate: EncodedTerm<I>,
pub object: EncodedTerm<I>,
pub graph_name: EncodedTerm<I>,
pub struct EncodedQuad {
pub subject: EncodedTerm,
pub predicate: EncodedTerm,
pub object: EncodedTerm,
pub graph_name: EncodedTerm,
}
impl<I: StrId> EncodedQuad<I> {
impl EncodedQuad {
pub fn new(
subject: EncodedTerm<I>,
predicate: EncodedTerm<I>,
object: EncodedTerm<I>,
graph_name: EncodedTerm<I>,
subject: EncodedTerm,
predicate: EncodedTerm,
object: EncodedTerm,
graph_name: EncodedTerm,
) -> Self {
Self {
subject,
@ -588,22 +489,20 @@ impl<I: StrId> EncodedQuad<I> {
pub(crate) trait StrEncodingAware {
//TODO: rename
type Error: Error + Into<EvaluationError> + 'static;
type StrId: StrId + 'static;
}
impl<'a, T: StrEncodingAware> StrEncodingAware for &'a T {
type Error = T::Error;
type StrId = T::StrId;
}
pub(crate) trait StrLookup: StrEncodingAware {
fn get_str(&self, id: Self::StrId) -> Result<Option<String>, Self::Error>;
fn get_str(&self, id: StrHash) -> Result<Option<String>, Self::Error>;
fn get_str_id(&self, value: &str) -> Result<Option<Self::StrId>, Self::Error>;
fn get_str_id(&self, value: &str) -> Result<Option<StrHash>, Self::Error>;
}
pub(crate) trait StrContainer: StrEncodingAware {
fn insert_str(&mut self, value: &str) -> Result<Self::StrId, Self::Error>;
fn insert_str(&mut self, value: &str) -> Result<StrHash, Self::Error>;
}
/// Tries to encode a term based on the existing strings (does not insert anything)
@ -611,7 +510,7 @@ pub(crate) trait ReadEncoder: StrEncodingAware {
fn get_encoded_named_node(
&self,
named_node: NamedNodeRef<'_>,
) -> Result<Option<EncodedTerm<Self::StrId>>, Self::Error> {
) -> Result<Option<EncodedTerm>, Self::Error> {
Ok(Some(EncodedTerm::NamedNode {
iri_id: if let Some(iri_id) = self.get_encoded_str(named_node.as_str())? {
iri_id
@ -624,7 +523,7 @@ pub(crate) trait ReadEncoder: StrEncodingAware {
fn get_encoded_blank_node(
&self,
blank_node: BlankNodeRef<'_>,
) -> Result<Option<EncodedTerm<Self::StrId>>, Self::Error> {
) -> Result<Option<EncodedTerm>, Self::Error> {
Ok(Some(if let Some(id) = blank_node.id() {
EncodedTerm::NumericalBlankNode { id }
} else {
@ -646,7 +545,7 @@ pub(crate) trait ReadEncoder: StrEncodingAware {
fn get_encoded_literal(
&self,
literal: LiteralRef<'_>,
) -> Result<Option<EncodedTerm<Self::StrId>>, Self::Error> {
) -> Result<Option<EncodedTerm>, Self::Error> {
let value = literal.value();
let datatype = literal.datatype().as_str();
Ok(Some(
@ -783,17 +682,14 @@ pub(crate) trait ReadEncoder: StrEncodingAware {
fn get_encoded_named_or_blank_node(
&self,
term: NamedOrBlankNodeRef<'_>,
) -> Result<Option<EncodedTerm<Self::StrId>>, Self::Error> {
) -> Result<Option<EncodedTerm>, Self::Error> {
match term {
NamedOrBlankNodeRef::NamedNode(named_node) => self.get_encoded_named_node(named_node),
NamedOrBlankNodeRef::BlankNode(blank_node) => self.get_encoded_blank_node(blank_node),
}
}
fn get_encoded_term(
&self,
term: TermRef<'_>,
) -> Result<Option<EncodedTerm<Self::StrId>>, Self::Error> {
fn get_encoded_term(&self, term: TermRef<'_>) -> Result<Option<EncodedTerm>, Self::Error> {
match term {
TermRef::NamedNode(named_node) => self.get_encoded_named_node(named_node),
TermRef::BlankNode(blank_node) => self.get_encoded_blank_node(blank_node),
@ -804,7 +700,7 @@ pub(crate) trait ReadEncoder: StrEncodingAware {
fn get_encoded_graph_name(
&self,
name: GraphNameRef<'_>,
) -> Result<Option<EncodedTerm<Self::StrId>>, Self::Error> {
) -> Result<Option<EncodedTerm>, Self::Error> {
match name {
GraphNameRef::NamedNode(named_node) => self.get_encoded_named_node(named_node),
GraphNameRef::BlankNode(blank_node) => self.get_encoded_blank_node(blank_node),
@ -812,10 +708,7 @@ pub(crate) trait ReadEncoder: StrEncodingAware {
}
}
fn get_encoded_quad(
&self,
quad: QuadRef<'_>,
) -> Result<Option<EncodedQuad<Self::StrId>>, Self::Error> {
fn get_encoded_quad(&self, quad: QuadRef<'_>) -> Result<Option<EncodedQuad>, Self::Error> {
Ok(Some(EncodedQuad {
subject: if let Some(subject) = self.get_encoded_named_or_blank_node(quad.subject)? {
subject
@ -840,11 +733,11 @@ pub(crate) trait ReadEncoder: StrEncodingAware {
}))
}
fn get_encoded_str(&self, value: &str) -> Result<Option<Self::StrId>, Self::Error>;
fn get_encoded_str(&self, value: &str) -> Result<Option<StrHash>, Self::Error>;
}
impl<S: StrLookup> ReadEncoder for S {
fn get_encoded_str(&self, value: &str) -> Result<Option<Self::StrId>, Self::Error> {
fn get_encoded_str(&self, value: &str) -> Result<Option<StrHash>, Self::Error> {
self.get_str_id(value)
}
}
@ -854,14 +747,14 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
fn encode_named_node(
&mut self,
named_node: NamedNodeRef<'_>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
) -> Result<EncodedTerm, Self::Error> {
self.encode_rio_named_node(named_node.into())
}
fn encode_blank_node(
&mut self,
blank_node: BlankNodeRef<'_>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
) -> Result<EncodedTerm, Self::Error> {
Ok(if let Some(id) = blank_node.id() {
EncodedTerm::NumericalBlankNode { id }
} else {
@ -876,24 +769,21 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
})
}
fn encode_literal(
&mut self,
literal: LiteralRef<'_>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
fn encode_literal(&mut self, literal: LiteralRef<'_>) -> Result<EncodedTerm, Self::Error> {
self.encode_rio_literal(literal.into())
}
fn encode_named_or_blank_node(
&mut self,
term: NamedOrBlankNodeRef<'_>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
) -> Result<EncodedTerm, Self::Error> {
match term {
NamedOrBlankNodeRef::NamedNode(named_node) => self.encode_named_node(named_node),
NamedOrBlankNodeRef::BlankNode(blank_node) => self.encode_blank_node(blank_node),
}
}
fn encode_term(&mut self, term: TermRef<'_>) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
fn encode_term(&mut self, term: TermRef<'_>) -> Result<EncodedTerm, Self::Error> {
match term {
TermRef::NamedNode(named_node) => self.encode_named_node(named_node),
TermRef::BlankNode(blank_node) => self.encode_blank_node(blank_node),
@ -901,10 +791,7 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
}
}
fn encode_graph_name(
&mut self,
name: GraphNameRef<'_>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
fn encode_graph_name(&mut self, name: GraphNameRef<'_>) -> Result<EncodedTerm, Self::Error> {
match name {
GraphNameRef::NamedNode(named_node) => self.encode_named_node(named_node),
GraphNameRef::BlankNode(blank_node) => self.encode_blank_node(blank_node),
@ -912,7 +799,7 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
}
}
fn encode_quad(&mut self, quad: QuadRef<'_>) -> Result<EncodedQuad<Self::StrId>, Self::Error> {
fn encode_quad(&mut self, quad: QuadRef<'_>) -> Result<EncodedQuad, Self::Error> {
Ok(EncodedQuad {
subject: self.encode_named_or_blank_node(quad.subject)?,
predicate: self.encode_named_node(quad.predicate)?,
@ -924,8 +811,8 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
fn encode_triple_in_graph(
&mut self,
triple: TripleRef<'_>,
graph_name: EncodedTerm<Self::StrId>,
) -> Result<EncodedQuad<Self::StrId>, Self::Error> {
graph_name: EncodedTerm,
) -> Result<EncodedQuad, Self::Error> {
Ok(EncodedQuad {
subject: self.encode_named_or_blank_node(triple.subject)?,
predicate: self.encode_named_node(triple.predicate)?,
@ -937,7 +824,7 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
fn encode_rio_named_node(
&mut self,
named_node: rio::NamedNode<'_>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
) -> Result<EncodedTerm, Self::Error> {
Ok(EncodedTerm::NamedNode {
iri_id: self.encode_str(named_node.iri)?,
})
@ -947,7 +834,7 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
&mut self,
blank_node: rio::BlankNode<'_>,
bnodes_map: &mut HashMap<String, u128>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
) -> Result<EncodedTerm, Self::Error> {
Ok(if let Some(id) = bnodes_map.get(blank_node.id) {
EncodedTerm::NumericalBlankNode { id: *id }
} else {
@ -959,7 +846,7 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
fn encode_rio_literal(
&mut self,
literal: rio::Literal<'_>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
) -> Result<EncodedTerm, Self::Error> {
Ok(match literal {
rio::Literal::Simple { value } => {
if let Ok(value) = SmallString::try_from(value) {
@ -1065,7 +952,7 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
&mut self,
term: rio::NamedOrBlankNode<'_>,
bnodes_map: &mut HashMap<String, u128>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
) -> Result<EncodedTerm, Self::Error> {
match term {
rio::NamedOrBlankNode::NamedNode(named_node) => self.encode_rio_named_node(named_node),
rio::NamedOrBlankNode::BlankNode(blank_node) => {
@ -1078,7 +965,7 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
&mut self,
term: rio::Term<'_>,
bnodes_map: &mut HashMap<String, u128>,
) -> Result<EncodedTerm<Self::StrId>, Self::Error> {
) -> Result<EncodedTerm, Self::Error> {
match term {
rio::Term::NamedNode(named_node) => self.encode_rio_named_node(named_node),
rio::Term::BlankNode(blank_node) => self.encode_rio_blank_node(blank_node, bnodes_map),
@ -1090,7 +977,7 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
&mut self,
quad: rio::Quad<'_>,
bnodes_map: &mut HashMap<String, u128>,
) -> Result<EncodedQuad<Self::StrId>, Self::Error> {
) -> Result<EncodedQuad, Self::Error> {
Ok(EncodedQuad {
subject: self.encode_rio_named_or_blank_node(quad.subject, bnodes_map)?,
predicate: self.encode_rio_named_node(quad.predicate)?,
@ -1105,9 +992,9 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
fn encode_rio_triple_in_graph(
&mut self,
triple: rio::Triple<'_>,
graph_name: EncodedTerm<Self::StrId>,
graph_name: EncodedTerm,
bnodes_map: &mut HashMap<String, u128>,
) -> Result<EncodedQuad<Self::StrId>, Self::Error> {
) -> Result<EncodedQuad, Self::Error> {
Ok(EncodedQuad {
subject: self.encode_rio_named_or_blank_node(triple.subject, bnodes_map)?,
predicate: self.encode_rio_named_node(triple.predicate)?,
@ -1116,16 +1003,16 @@ pub(crate) trait WriteEncoder: StrEncodingAware {
})
}
fn encode_str(&mut self, value: &str) -> Result<Self::StrId, Self::Error>;
fn encode_str(&mut self, value: &str) -> Result<StrHash, Self::Error>;
}
impl<S: StrContainer> WriteEncoder for S {
fn encode_str(&mut self, value: &str) -> Result<Self::StrId, Self::Error> {
fn encode_str(&mut self, value: &str) -> Result<StrHash, Self::Error> {
self.insert_str(value)
}
}
pub fn parse_boolean_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_boolean_str(value: &str) -> Option<EncodedTerm> {
match value {
"true" | "1" => Some(EncodedTerm::BooleanLiteral(true)),
"false" | "0" => Some(EncodedTerm::BooleanLiteral(false)),
@ -1133,78 +1020,75 @@ pub fn parse_boolean_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
}
}
pub fn parse_float_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_float_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::FloatLiteral).ok()
}
pub fn parse_double_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_double_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::DoubleLiteral).ok()
}
pub fn parse_integer_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_integer_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::IntegerLiteral).ok()
}
pub fn parse_decimal_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_decimal_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::DecimalLiteral).ok()
}
pub fn parse_date_time_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_date_time_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::DateTimeLiteral).ok()
}
pub fn parse_time_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_time_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::TimeLiteral).ok()
}
pub fn parse_date_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_date_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::DateLiteral).ok()
}
pub fn parse_g_year_month_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_g_year_month_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::GYearMonthLiteral).ok()
}
pub fn parse_g_year_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_g_year_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::GYearLiteral).ok()
}
pub fn parse_g_month_day_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_g_month_day_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::GMonthDayLiteral).ok()
}
pub fn parse_g_day_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_g_day_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::GDayLiteral).ok()
}
pub fn parse_g_month_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_g_month_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::GMonthLiteral).ok()
}
pub fn parse_duration_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_duration_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::DurationLiteral).ok()
}
pub fn parse_year_month_duration_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_year_month_duration_str(value: &str) -> Option<EncodedTerm> {
value
.parse()
.map(EncodedTerm::YearMonthDurationLiteral)
.ok()
}
pub fn parse_day_time_duration_str<I: StrId>(value: &str) -> Option<EncodedTerm<I>> {
pub fn parse_day_time_duration_str(value: &str) -> Option<EncodedTerm> {
value.parse().map(EncodedTerm::DayTimeDurationLiteral).ok()
}
pub(crate) trait Decoder: StrLookup {
fn decode_term(
&self,
encoded: EncodedTerm<Self::StrId>,
) -> Result<Term, DecoderError<Self::Error>>;
fn decode_term(&self, encoded: EncodedTerm) -> Result<Term, DecoderError<Self::Error>>;
fn decode_named_or_blank_node(
&self,
encoded: EncodedTerm<Self::StrId>,
encoded: EncodedTerm,
) -> Result<NamedOrBlankNode, DecoderError<Self::Error>> {
match self.decode_term(encoded)? {
Term::NamedNode(named_node) => Ok(named_node.into()),
@ -1217,7 +1101,7 @@ pub(crate) trait Decoder: StrLookup {
fn decode_named_node(
&self,
encoded: EncodedTerm<Self::StrId>,
encoded: EncodedTerm,
) -> Result<NamedNode, DecoderError<Self::Error>> {
match self.decode_term(encoded)? {
Term::NamedNode(named_node) => Ok(named_node),
@ -1230,10 +1114,7 @@ pub(crate) trait Decoder: StrLookup {
}
}
fn decode_triple(
&self,
encoded: &EncodedQuad<Self::StrId>,
) -> Result<Triple, DecoderError<Self::Error>> {
fn decode_triple(&self, encoded: &EncodedQuad) -> Result<Triple, DecoderError<Self::Error>> {
Ok(Triple::new(
self.decode_named_or_blank_node(encoded.subject)?,
self.decode_named_node(encoded.predicate)?,
@ -1241,10 +1122,7 @@ pub(crate) trait Decoder: StrLookup {
))
}
fn decode_quad(
&self,
encoded: &EncodedQuad<Self::StrId>,
) -> Result<Quad, DecoderError<Self::Error>> {
fn decode_quad(&self, encoded: &EncodedQuad) -> Result<Quad, DecoderError<Self::Error>> {
Ok(Quad::new(
self.decode_named_or_blank_node(encoded.subject)?,
self.decode_named_node(encoded.predicate)?,
@ -1258,10 +1136,7 @@ pub(crate) trait Decoder: StrLookup {
}
impl<S: StrLookup> Decoder for S {
fn decode_term(
&self,
encoded: EncodedTerm<Self::StrId>,
) -> Result<Term, DecoderError<Self::Error>> {
fn decode_term(&self, encoded: EncodedTerm) -> Result<Term, DecoderError<Self::Error>> {
match encoded {
EncodedTerm::DefaultGraph => Err(DecoderError::Decoder {
msg: "The default graph tag is not a valid term".to_owned(),
@ -1340,7 +1215,7 @@ impl<S: StrLookup> Decoder for S {
fn get_required_str<L: StrLookup>(
lookup: &L,
id: L::StrId,
id: StrHash,
) -> Result<String, DecoderError<L::Error>> {
lookup
.get_str(id)

@ -76,8 +76,8 @@ pub struct SledStore {
graphs: Tree,
}
type EncodedTerm = crate::store::numeric_encoder::EncodedTerm<StrHash>;
type EncodedQuad = crate::store::numeric_encoder::EncodedQuad<StrHash>;
type EncodedTerm = crate::store::numeric_encoder::EncodedTerm;
type EncodedQuad = crate::store::numeric_encoder::EncodedQuad;
//TODO: indexes for the default graph and indexes for the named graphs (no more Optional and space saving)
@ -902,7 +902,6 @@ impl fmt::Display for SledStore {
impl StrEncodingAware for SledStore {
type Error = io::Error;
type StrId = StrHash;
}
impl StrLookup for SledStore {
@ -1280,7 +1279,6 @@ impl SledTransaction<'_> {
impl<'a> StrEncodingAware for &'a SledTransaction<'a> {
type Error = SledUnabortableTransactionError;
type StrId = StrHash;
}
impl<'a> StrLookup for &'a SledTransaction<'a> {

Loading…
Cancel
Save