SPARQL: Fixes DISTINCT after ORDER BY

pull/10/head
Tpt 6 years ago
parent 52463b59db
commit 4ac6828311
  1. 33
      lib/src/sparql/eval.rs
  2. 5
      lib/tests/sparql_test_cases.rs

@ -295,17 +295,8 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
} }
PlanNode::HashDeduplicate { child } => { PlanNode::HashDeduplicate { child } => {
let iter = self.eval_plan(&*child, from); let iter = self.eval_plan(&*child, from);
let mut values = HashSet::with_capacity(iter.size_hint().0); let already_seen = HashSet::with_capacity(iter.size_hint().0);
let mut errors = Vec::default(); Box::new(HashDeduplicateIterator { iter, already_seen })
for result in iter {
match result {
Ok(result) => {
values.insert(result);
}
Err(error) => errors.push(Err(error)),
}
}
Box::new(errors.into_iter().chain(values.into_iter().map(Ok)))
} }
PlanNode::Skip { child, count } => Box::new(self.eval_plan(&*child, from).skip(*count)), PlanNode::Skip { child, count } => Box::new(self.eval_plan(&*child, from).skip(*count)),
PlanNode::Limit { child, count } => { PlanNode::Limit { child, count } => {
@ -1048,6 +1039,26 @@ impl<'a, S: EncodedQuadsStore> Iterator for UnionIterator<'a, S> {
} }
} }
struct HashDeduplicateIterator<'a> {
iter: EncodedTuplesIterator<'a>,
already_seen: HashSet<EncodedTuple>,
}
impl<'a> Iterator for HashDeduplicateIterator<'a> {
type Item = Result<EncodedTuple>;
fn next(&mut self) -> Option<Result<EncodedTuple>> {
match self.iter.next()? {
Ok(tuple) => if self.already_seen.insert(tuple.clone()) {
Some(Ok(tuple))
} else {
self.next()
},
Err(error) => Some(Err(error)),
}
}
}
struct ConstructIterator<'a, S: EncodedQuadsStore> { struct ConstructIterator<'a, S: EncodedQuadsStore> {
store: Arc<S>, store: Arc<S>,
iter: EncodedTuplesIterator<'a>, iter: EncodedTuplesIterator<'a>,

@ -82,6 +82,7 @@ fn sparql_w3c_syntax_testsuite() {
#[test] #[test]
fn sparql_w3c_query_evaluation_testsuite() { fn sparql_w3c_query_evaluation_testsuite() {
//TODO: dataset graph open-world regex
let manifest_10_urls = vec![ let manifest_10_urls = vec![
Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest.ttl") Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/algebra/manifest.ttl")
.unwrap(), .unwrap(),
@ -115,6 +116,10 @@ fn sparql_w3c_query_evaluation_testsuite() {
).unwrap(), ).unwrap(),
Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional/manifest.ttl") Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/optional/manifest.ttl")
.unwrap(), .unwrap(),
Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/reduced/manifest.ttl")
.unwrap(),
Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/solution-seq/manifest.ttl")
.unwrap(),
Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/sort/manifest.ttl").unwrap(), Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/sort/manifest.ttl").unwrap(),
Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/triple-match/manifest.ttl") Url::parse("http://www.w3.org/2001/sw/DataAccess/tests/data-r2/triple-match/manifest.ttl")
.unwrap(), .unwrap(),

Loading…
Cancel
Save