Removes PlanExpression::In

Can be expressed with Or and Equals
pull/171/head
Tpt 3 years ago
parent 4f7e396af0
commit bb5431b545
  1. 25
      lib/src/sparql/eval.rs
  2. 7
      lib/src/sparql/plan.rs
  3. 18
      lib/src/sparql/plan_builder.rs

@ -992,31 +992,6 @@ impl SimpleEvaluator {
)
})
}
PlanExpression::In(e, l) => {
let e = self.expression_evaluator(e);
let l: Vec<_> = l
.iter()
.map(|possible| self.expression_evaluator(possible))
.collect();
Rc::new(move |tuple| {
let needed = e(tuple)?;
let mut error = false;
for possible in &l {
if let Some(possible) = possible(tuple) {
if Some(true) == equals(&needed, &possible) {
return Some(true.into());
}
} else {
error = true;
}
}
if error {
None
} else {
Some(false.into())
}
})
}
PlanExpression::Add(a, b) => {
let a = self.expression_evaluator(a);
let b = self.expression_evaluator(b);

@ -216,7 +216,6 @@ pub enum PlanExpression {
GreaterOrEqual(Box<Self>, Box<Self>),
Less(Box<Self>, Box<Self>),
LessOrEqual(Box<Self>, Box<Self>),
In(Box<Self>, Vec<Self>),
Add(Box<Self>, Box<Self>),
Subtract(Box<Self>, Box<Self>),
Multiply(Box<Self>, Box<Self>),
@ -400,12 +399,6 @@ impl PlanExpression {
e.add_maybe_bound_variables(set);
}
}
PlanExpression::In(a, bs) => {
a.add_maybe_bound_variables(set);
for b in bs {
b.add_maybe_bound_variables(set);
}
}
PlanExpression::Exists(e) => {
e.add_maybe_bound_variables(set);
}

@ -363,10 +363,20 @@ impl<'a> PlanBuilder<'a> {
Box::new(self.build_for_expression(a, variables, graph_name)?),
Box::new(self.build_for_expression(b, variables, graph_name)?),
),
Expression::In(e, l) => PlanExpression::In(
Box::new(self.build_for_expression(e, variables, graph_name)?),
self.expression_list(l, variables, graph_name)?,
),
Expression::In(e, l) => {
let e = self.build_for_expression(e, variables, graph_name)?;
l.iter()
.map(|v| {
Ok(PlanExpression::Equal(
Box::new(e.clone()),
Box::new(self.build_for_expression(v, variables, graph_name)?),
))
})
.reduce(|a: Result<_, EvaluationError>, b| {
Ok(PlanExpression::Or(Box::new(a?), Box::new(b?)))
})
.unwrap_or_else(|| Ok(PlanExpression::Constant(false.into())))?
}
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)?),

Loading…
Cancel
Save