Fixes empty IN expression optimization

pull/516/head
Tpt 2 years ago committed by Thomas Tanon
parent 0a064a8704
commit 4cc9e4008b
  1. 17
      lib/src/sparql/plan_builder.rs
  2. 1
      testsuite/oxigraph-tests/sparql/in_empty_error.rq
  3. 9
      testsuite/oxigraph-tests/sparql/in_empty_error.srx
  4. 6
      testsuite/oxigraph-tests/sparql/manifest.ttl

@ -432,13 +432,21 @@ impl<'a> PlanBuilder<'a> {
Box::new(self.build_for_expression(b, variables, graph_name)?),
),
Expression::In(e, l) => {
let e = self.build_for_expression(e, variables, graph_name)?;
if l.is_empty() {
return Ok(PlanExpression::Literal(PlanTerm {
// False except on error
PlanExpression::If(
Box::new(e),
Box::new(PlanExpression::Literal(PlanTerm {
encoded: false.into(),
plain: false.into(),
}));
}
let e = self.build_for_expression(e, variables, graph_name)?;
})),
Box::new(PlanExpression::Literal(PlanTerm {
encoded: false.into(),
plain: false.into(),
})),
)
} else {
PlanExpression::Or(
l.iter()
.map(|v| {
@ -450,6 +458,7 @@ impl<'a> PlanBuilder<'a> {
.collect::<Result<_, EvaluationError>>()?,
)
}
}
Expression::Add(a, b) => PlanExpression::Add(
Box::new(self.build_for_expression(a, variables, graph_name)?),
Box::new(self.build_for_expression(b, variables, graph_name)?),

@ -0,0 +1 @@
SELECT ?r WHERE { BIND((?foo IN ()) AS ?r) }

@ -0,0 +1,9 @@
<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
<head>
<variable name="r"/>
</head>
<results>
<result></result>
</results>
</sparql>

@ -30,6 +30,7 @@
:unbound_variable_in_subquery
:one_or_more_shared
:one_or_more_star
:in_empty_error
) .
:small_unicode_escape_with_multibytes_char rdf:type mf:NegativeSyntaxTest ;
@ -140,3 +141,8 @@
[ qt:query <one_or_more_star.rq> ;
qt:data <one_or_more_star.ttl> ] ;
mf:result <one_or_more_star.srx> .
:in_empty_error rdf:type mf:QueryEvaluationTest ;
mf:name "IN should propagate errors on the left side, even on the empty input" ;
mf:action [ qt:query <in_empty_error.rq> ] ;
mf:result <in_empty_error.srx> .

Loading…
Cancel
Save