|
|
@ -1,16 +1,17 @@ |
|
|
|
use crate::sparql::algebra::QueryDataset; |
|
|
|
use crate::sparql::algebra::QueryDataset; |
|
|
|
use crate::sparql::EvaluationError; |
|
|
|
use crate::sparql::EvaluationError; |
|
|
|
use crate::store::numeric_encoder::{ |
|
|
|
use crate::store::numeric_encoder::{ |
|
|
|
EncodedQuad, EncodedTerm, ReadEncoder, StrContainer, StrEncodingAware, StrId, StrLookup, |
|
|
|
EncodedQuad, EncodedTerm, ReadEncoder, StrContainer, StrEncodingAware, StrHash, StrId, |
|
|
|
|
|
|
|
StrLookup, |
|
|
|
}; |
|
|
|
}; |
|
|
|
use crate::store::ReadableEncodedStore; |
|
|
|
use crate::store::ReadableEncodedStore; |
|
|
|
use lasso::{Rodeo, Spur}; |
|
|
|
|
|
|
|
use std::cell::RefCell; |
|
|
|
use std::cell::RefCell; |
|
|
|
|
|
|
|
use std::collections::HashMap; |
|
|
|
use std::iter::{empty, once, Once}; |
|
|
|
use std::iter::{empty, once, Once}; |
|
|
|
|
|
|
|
|
|
|
|
pub(crate) struct DatasetView<S: ReadableEncodedStore> { |
|
|
|
pub(crate) struct DatasetView<S: ReadableEncodedStore> { |
|
|
|
store: S, |
|
|
|
store: S, |
|
|
|
extra: RefCell<Rodeo>, |
|
|
|
extra: RefCell<HashMap<StrHash, String>>, |
|
|
|
dataset: EncodedDatasetSpec<S::StrId>, |
|
|
|
dataset: EncodedDatasetSpec<S::StrId>, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -44,7 +45,7 @@ impl<S: ReadableEncodedStore> DatasetView<S> { |
|
|
|
}; |
|
|
|
}; |
|
|
|
Ok(Self { |
|
|
|
Ok(Self { |
|
|
|
store, |
|
|
|
store, |
|
|
|
extra: RefCell::new(Rodeo::default()), |
|
|
|
extra: RefCell::new(HashMap::default()), |
|
|
|
dataset, |
|
|
|
dataset, |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
@ -160,14 +161,13 @@ impl<S: ReadableEncodedStore> StrLookup for DatasetView<S> { |
|
|
|
fn get_str(&self, id: DatasetStrId<S::StrId>) -> Result<Option<String>, EvaluationError> { |
|
|
|
fn get_str(&self, id: DatasetStrId<S::StrId>) -> Result<Option<String>, EvaluationError> { |
|
|
|
match id { |
|
|
|
match id { |
|
|
|
DatasetStrId::Store(id) => self.store.get_str(id).map_err(|e| e.into()), |
|
|
|
DatasetStrId::Store(id) => self.store.get_str(id).map_err(|e| e.into()), |
|
|
|
DatasetStrId::Temporary(id) => { |
|
|
|
DatasetStrId::Temporary(id) => Ok(self.extra.borrow().get(&id).cloned()), |
|
|
|
Ok(self.extra.borrow().try_resolve(&id).map(|e| e.to_owned())) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_str_id(&self, value: &str) -> Result<Option<DatasetStrId<S::StrId>>, EvaluationError> { |
|
|
|
fn get_str_id(&self, value: &str) -> Result<Option<DatasetStrId<S::StrId>>, EvaluationError> { |
|
|
|
if let Some(id) = self.extra.borrow().get(value) { |
|
|
|
let id = StrHash::new(value); |
|
|
|
|
|
|
|
if self.extra.borrow().contains_key(&id) { |
|
|
|
Ok(Some(DatasetStrId::Temporary(id))) |
|
|
|
Ok(Some(DatasetStrId::Temporary(id))) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Ok(self |
|
|
|
Ok(self |
|
|
@ -272,9 +272,12 @@ impl<'a, S: ReadableEncodedStore> StrContainer for &'a DatasetView<S> { |
|
|
|
if let Some(id) = self.store.get_str_id(value).map_err(|e| e.into())? { |
|
|
|
if let Some(id) = self.store.get_str_id(value).map_err(|e| e.into())? { |
|
|
|
Ok(DatasetStrId::Store(id)) |
|
|
|
Ok(DatasetStrId::Store(id)) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
Ok(DatasetStrId::Temporary( |
|
|
|
let hash = StrHash::new(value); |
|
|
|
self.extra.borrow_mut().get_or_intern(value), |
|
|
|
self.extra |
|
|
|
)) |
|
|
|
.borrow_mut() |
|
|
|
|
|
|
|
.entry(hash) |
|
|
|
|
|
|
|
.or_insert_with(|| value.to_owned()); |
|
|
|
|
|
|
|
Ok(DatasetStrId::Temporary(hash)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -282,7 +285,7 @@ impl<'a, S: ReadableEncodedStore> StrContainer for &'a DatasetView<S> { |
|
|
|
#[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)] |
|
|
|
#[derive(Eq, PartialEq, Debug, Copy, Clone, Hash)] |
|
|
|
pub enum DatasetStrId<I: StrId> { |
|
|
|
pub enum DatasetStrId<I: StrId> { |
|
|
|
Store(I), |
|
|
|
Store(I), |
|
|
|
Temporary(Spur), |
|
|
|
Temporary(StrHash), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
impl<I: StrId> StrId for DatasetStrId<I> {} |
|
|
|
impl<I: StrId> StrId for DatasetStrId<I> {} |
|
|
|