Variable should stay not bound in subqueries even if they are bound in the parent query

Closes #261
pull/263/head
Tpt 2 years ago committed by Thomas Tanon
parent becb64b80b
commit d16033ba66
  1. 31
      lib/src/sparql/eval.rs
  2. 7
      testsuite/oxigraph-tests/sparql/manifest.ttl
  3. 6
      testsuite/oxigraph-tests/sparql/unbound_variable_in_subquery.rq
  4. 17
      testsuite/oxigraph-tests/sparql/unbound_variable_in_subquery.srx

@ -531,23 +531,32 @@ impl SimpleEvaluator {
let mapping = mapping.clone();
Rc::new(move |from| {
let mapping = mapping.clone();
// We map forward the "from" values to make sure we join wit them
let mut inner_from = EncodedTuple::with_capacity(mapping.len());
for (input_key, output_key) in mapping.iter() {
if let Some(value) = from.get(*output_key) {
inner_from.set(*input_key, value.clone());
}
}
Box::new(child(inner_from).map(move |tuple| {
let tuple = tuple?;
Box::new(
child(EncodedTuple::with_capacity(mapping.len())).filter_map(
move |tuple| {
match tuple {
Ok(tuple) => {
let mut output_tuple = from.clone();
for (input_key, output_key) in mapping.iter() {
if let Some(value) = tuple.get(*input_key) {
if let Some(existing_value) =
output_tuple.get(*output_key)
{
if existing_value != value {
return None; // Conflict
}
} else {
output_tuple.set(*output_key, value.clone());
}
}
Ok(output_tuple)
}))
}
Some(Ok(output_tuple))
}
Err(e) => Some(Err(e)),
}
},
),
)
})
}
PlanNode::Aggregate {

@ -27,6 +27,7 @@
:nested_expression
:order_terms
:nested_anonymous
:unbound_variable_in_subquery
) .
:small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ;
@ -122,3 +123,9 @@
[ qt:query <nested_anonymous.rq> ;
qt:data <nested_anonymous.ttl> ] ;
mf:result <nested_anonymous.srx> .
:unbound_variable_in_subquery rdf:type mf:QueryEvaluationTest ;
mf:name "Variable should stay not bound in subqueries even if they are bound in the parent query" ;
mf:action
[ qt:query <unbound_variable_in_subquery.rq> ] ;
mf:result <unbound_variable_in_subquery.srx> .

@ -0,0 +1,6 @@
PREFIX ex: <http://example.com/>
SELECT ?a ?b WHERE {
BIND(ex:a as ?a)
{SELECT ?b WHERE { BIND(ex:b as ?b) FILTER(!BOUND(?a))}}
}

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="a"/>
<variable name="b"/>
</head>
<results>
<result>
<binding name="a">
<uri>http://example.com/a</uri>
</binding>
<binding name="b">
<uri>http://example.com/b</uri>
</binding>
</result>
</results>
</sparql>
Loading…
Cancel
Save