diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index e243912e..a59daf96 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -212,25 +212,9 @@ impl SimpleEvaluator { PlanExpression::UnaryNot(e) => self .to_bool(self.eval_expression(e, tuple)?) .map(|v| (!v).into()), - PlanExpression::Str(e) => match self.eval_expression(e, tuple)? { - EncodedTerm::NamedNode { iri_id } => { - 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::Str(e) => Some(EncodedTerm::SimpleLiteral { + value_id: self.to_string_id(self.eval_expression(e, tuple)?)?, + }), PlanExpression::Lang(e) => match self.eval_expression(e, tuple)? { EncodedTerm::LangStringLiteral { language_id, .. } => { Some(EncodedTerm::SimpleLiteral { @@ -272,6 +256,12 @@ impl SimpleEvaluator { PlanExpression::IsLiteral(e) => { 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!(), } } @@ -285,6 +275,21 @@ impl SimpleEvaluator { } } + fn to_string_id(&self, term: EncodedTerm) -> Option { + 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( &self, iter: EncodedTuplesIterator,