Fixes empty IN expression optimization

pull/516/head
Tpt 1 year ago committed by Thomas Tanon
parent 0a064a8704
commit 4cc9e4008b
  1. 39
      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,23 +432,32 @@ 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 {
encoded: false.into(),
plain: false.into(),
}));
// False except on error
PlanExpression::If(
Box::new(e),
Box::new(PlanExpression::Literal(PlanTerm {
encoded: false.into(),
plain: false.into(),
})),
Box::new(PlanExpression::Literal(PlanTerm {
encoded: false.into(),
plain: false.into(),
})),
)
} else {
PlanExpression::Or(
l.iter()
.map(|v| {
Ok(PlanExpression::Equal(
Box::new(e.clone()),
Box::new(self.build_for_expression(v, variables, graph_name)?),
))
})
.collect::<Result<_, EvaluationError>>()?,
)
}
let e = self.build_for_expression(e, variables, graph_name)?;
PlanExpression::Or(
l.iter()
.map(|v| {
Ok(PlanExpression::Equal(
Box::new(e.clone()),
Box::new(self.build_for_expression(v, variables, graph_name)?),
))
})
.collect::<Result<_, EvaluationError>>()?,
)
}
Expression::Add(a, b) => PlanExpression::Add(
Box::new(self.build_for_expression(a, 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