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

@ -27,6 +27,7 @@
:nested_expression :nested_expression
:order_terms :order_terms
:nested_anonymous :nested_anonymous
:unbound_variable_in_subquery
) . ) .
:small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ; :small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ;
@ -122,3 +123,9 @@
[ qt:query <nested_anonymous.rq> ; [ qt:query <nested_anonymous.rq> ;
qt:data <nested_anonymous.ttl> ] ; qt:data <nested_anonymous.ttl> ] ;
mf:result <nested_anonymous.srx> . 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