SERVICE SILENT should not remove tuple on failure

See: https://www.w3.org/TR/sparql11-federated-query/#serviceFailure
pull/21/head
Tpt 5 years ago
parent a1fcb6a9b7
commit 96837fb64d
  1. 24
      lib/src/sparql/eval.rs
  2. 3
      lib/tests/service_test_cases.rs

@ -128,11 +128,15 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator<S> {
service_name, service_name,
graph_pattern, graph_pattern,
.. ..
} => match self.evaluate_service(service_name, graph_pattern, variables, from) { } => match self.evaluate_service(service_name, graph_pattern, variables) {
Ok(result) => result, Ok(result) => Box::new(result.flat_map(move |binding| {
binding
.map(|binding| combine_tuples(&binding, &from))
.transpose()
})),
Err(e) => { Err(e) => {
if *silent { if *silent {
Box::new(empty()) Box::new(once(Ok(from)))
} else { } else {
Box::new(once(Err(e))) Box::new(once(Err(e)))
} }
@ -484,22 +488,14 @@ impl<'a, S: StoreConnection + 'a> SimpleEvaluator<S> {
service_name: &PatternValue, service_name: &PatternValue,
graph_pattern: &'b GraphPattern, graph_pattern: &'b GraphPattern,
variables: &'b [Variable], variables: &'b [Variable],
from: EncodedTuple,
) -> Result<EncodedTuplesIterator<'b>> { ) -> Result<EncodedTuplesIterator<'b>> {
let service_name = self.dataset.decode_named_node( let service_name = self.dataset.decode_named_node(
get_pattern_value(service_name, &[]) get_pattern_value(service_name, &[])
.ok_or_else(|| format_err!("The SERVICE name is not bound"))?, .ok_or_else(|| format_err!("The SERVICE name is not bound"))?,
)?; )?;
Ok(Box::new( Ok(self.encode_bindings(
self.encode_bindings( variables,
variables, self.service_handler.handle(&service_name, &graph_pattern)?,
self.service_handler.handle(&service_name, &graph_pattern)?,
)
.flat_map(move |binding| {
binding
.map(|binding| combine_tuples(&binding, &from))
.transpose()
}),
)) ))
} }

@ -149,8 +149,7 @@ fn silent_service_empty_set_test() {
.into_values_iter() .into_values_iter()
.map(move |b| b.unwrap()) .map(move |b| b.unwrap())
.collect::<Vec<_>>(); .collect::<Vec<_>>();
println!("Collected: {:?}", collected); assert_eq!(collected.len(), 1);
assert_eq!(collected.len(), 0);
} }
#[test] #[test]

Loading…
Cancel
Save