Adds some cast evaluation

pull/10/head
Tpt 6 years ago
parent a9992af22a
commit ea7f61dc1b
  1. 43
      lib/src/sparql/eval.rs

@ -212,25 +212,9 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
PlanExpression::UnaryNot(e) => self PlanExpression::UnaryNot(e) => self
.to_bool(self.eval_expression(e, tuple)?) .to_bool(self.eval_expression(e, tuple)?)
.map(|v| (!v).into()), .map(|v| (!v).into()),
PlanExpression::Str(e) => match self.eval_expression(e, tuple)? { PlanExpression::Str(e) => Some(EncodedTerm::SimpleLiteral {
EncodedTerm::NamedNode { iri_id } => { value_id: self.to_string_id(self.eval_expression(e, tuple)?)?,
Some(EncodedTerm::SimpleLiteral { value_id: iri_id }) }),
}
EncodedTerm::SimpleLiteral { value_id } => {
Some(EncodedTerm::SimpleLiteral { value_id })
}
EncodedTerm::LangStringLiteral { value_id, .. } => {
Some(EncodedTerm::SimpleLiteral { value_id })
}
EncodedTerm::TypedLiteral { value_id, .. } => {
Some(EncodedTerm::SimpleLiteral { value_id })
}
EncodedTerm::StringLiteral { value_id } => {
Some(EncodedTerm::SimpleLiteral { value_id })
}
//TODO EncodedTerm::BooleanLiteral(v),
_ => None,
},
PlanExpression::Lang(e) => match self.eval_expression(e, tuple)? { PlanExpression::Lang(e) => match self.eval_expression(e, tuple)? {
EncodedTerm::LangStringLiteral { language_id, .. } => { EncodedTerm::LangStringLiteral { language_id, .. } => {
Some(EncodedTerm::SimpleLiteral { Some(EncodedTerm::SimpleLiteral {
@ -272,6 +256,12 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
PlanExpression::IsLiteral(e) => { PlanExpression::IsLiteral(e) => {
Some(self.eval_expression(e, tuple)?.is_literal().into()) Some(self.eval_expression(e, tuple)?.is_literal().into())
} }
PlanExpression::BooleanCast(e) => {
Some(self.to_bool(self.eval_expression(e, tuple)?)?.into())
}
PlanExpression::StringCast(e) => Some(EncodedTerm::StringLiteral {
value_id: self.to_string_id(self.eval_expression(e, tuple)?)?,
}),
e => unimplemented!(), e => unimplemented!(),
} }
} }
@ -285,6 +275,21 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
} }
} }
fn to_string_id(&self, term: EncodedTerm) -> Option<u64> {
match term {
EncodedTerm::NamedNode { iri_id } => Some(iri_id),
EncodedTerm::SimpleLiteral { value_id } => Some(value_id),
EncodedTerm::LangStringLiteral { value_id, .. } => Some(value_id),
EncodedTerm::TypedLiteral { value_id, .. } => Some(value_id),
EncodedTerm::StringLiteral { value_id } => Some(value_id),
EncodedTerm::BooleanLiteral(value) => self
.store
.insert_bytes(if value { b"true" } else { b"false" })
.ok(),
_ => None,
}
}
fn decode_bindings( fn decode_bindings(
&self, &self,
iter: EncodedTuplesIterator, iter: EncodedTuplesIterator,

Loading…
Cancel
Save