diff --git a/lib/src/sparql/eval.rs b/lib/src/sparql/eval.rs index 2d8ada8e..375b6323 100644 --- a/lib/src/sparql/eval.rs +++ b/lib/src/sparql/eval.rs @@ -483,6 +483,42 @@ impl SimpleEvaluator { }, None => Some(BlankNode::default().into()), }, + PlanExpression::Year(e) => match self.eval_expression(e, tuple)? { + EncodedTerm::NaiveDate(date) => Some(date.year().into()), + EncodedTerm::DateTime(date_time) => Some(date_time.year().into()), + EncodedTerm::NaiveDateTime(date_time) => Some(date_time.year().into()), + _ => None + }, + PlanExpression::Month(e) => match self.eval_expression(e, tuple)? { + EncodedTerm::NaiveDate(date) => Some(date.month().into()), + EncodedTerm::DateTime(date_time) => Some(date_time.month().into()), + EncodedTerm::NaiveDateTime(date_time) => Some(date_time.month().into()), + _ => None + }, + PlanExpression::Day(e) => match self.eval_expression(e, tuple)? { + EncodedTerm::NaiveDate(date) => Some(date.day().into()), + EncodedTerm::DateTime(date_time) => Some(date_time.day().into()), + EncodedTerm::NaiveDateTime(date_time) => Some(date_time.day().into()), + _ => None + }, + PlanExpression::Hours(e) => match self.eval_expression(e, tuple)? { + EncodedTerm::NaiveTime(time) => Some(time.hour().into()), + EncodedTerm::DateTime(date_time) => Some(date_time.hour().into()), + EncodedTerm::NaiveDateTime(date_time) => Some(date_time.hour().into()), + _ => None + }, + PlanExpression::Minutes(e) => match self.eval_expression(e, tuple)? { + EncodedTerm::NaiveTime(time) => Some(time.minute().into()), + EncodedTerm::DateTime(date_time) => Some(date_time.minute().into()), + EncodedTerm::NaiveDateTime(date_time) => Some(date_time.minute().into()), + _ => None + }, + PlanExpression::Seconds(e) => match self.eval_expression(e, tuple)? { + EncodedTerm::NaiveTime(time) => Some(time.second().into()), + EncodedTerm::DateTime(date_time) => Some(date_time.second().into()), + EncodedTerm::NaiveDateTime(date_time) => Some(date_time.second().into()), + _ => None + }, PlanExpression::UUID() => Some(EncodedTerm::NamedNode { iri_id: self .store diff --git a/lib/src/sparql/plan.rs b/lib/src/sparql/plan.rs index 13e476d3..fc3e506f 100644 --- a/lib/src/sparql/plan.rs +++ b/lib/src/sparql/plan.rs @@ -206,14 +206,15 @@ pub enum PlanExpression { StrStarts(Box, Box), StrEnds(Box, Box), StrBefore(Box, Box), - StrAfter(Box, Box), + StrAfter(Box, Box),*/ Year(Box), Month(Box), Day(Box), Hours(Box), Minutes(Box), Seconds(Box), - Timezone(Box), + /*Timezone(Box), + Tz(Box), Now(),*/ UUID(), StrUUID(), @@ -288,6 +289,12 @@ impl PlanExpression { | PlanExpression::Datatype(e) | PlanExpression::IRI(e) | PlanExpression::BNode(Some(e)) + | PlanExpression::Year(e) + | PlanExpression::Month(e) + | PlanExpression::Day(e) + | PlanExpression::Hours(e) + | PlanExpression::Minutes(e) + | PlanExpression::Seconds(e) | PlanExpression::IsIRI(e) | PlanExpression::IsBlank(e) | PlanExpression::IsLiteral(e) @@ -630,6 +637,24 @@ impl<'a, S: EncodedQuadsStore> PlanBuilder<'a, S> { Some(e) => Some(Box::new(self.build_for_expression(e, variables)?)), None => None, }), + Expression::YearFunctionCall(e) => { + PlanExpression::Year(Box::new(self.build_for_expression(e, variables)?)) + } + Expression::MonthFunctionCall(e) => { + PlanExpression::Month(Box::new(self.build_for_expression(e, variables)?)) + } + Expression::DayFunctionCall(e) => { + PlanExpression::Day(Box::new(self.build_for_expression(e, variables)?)) + } + Expression::HoursFunctionCall(e) => { + PlanExpression::Hours(Box::new(self.build_for_expression(e, variables)?)) + } + Expression::MinutesFunctionCall(e) => { + PlanExpression::Minutes(Box::new(self.build_for_expression(e, variables)?)) + } + Expression::SecondsFunctionCall(e) => { + PlanExpression::Seconds(Box::new(self.build_for_expression(e, variables)?)) + } Expression::UUIDFunctionCall() => PlanExpression::UUID(), Expression::StrUUIDFunctionCall() => PlanExpression::StrUUID(), Expression::CoalesceFunctionCall(l) => { diff --git a/lib/src/store/numeric_encoder.rs b/lib/src/store/numeric_encoder.rs index 86203ace..e09d417c 100644 --- a/lib/src/store/numeric_encoder.rs +++ b/lib/src/store/numeric_encoder.rs @@ -298,6 +298,18 @@ impl From for EncodedTerm { } } +impl From for EncodedTerm { + fn from(value: i32) -> Self { + EncodedTerm::IntegerLiteral(value as i128) + } +} + +impl From for EncodedTerm { + fn from(value: u32) -> Self { + EncodedTerm::IntegerLiteral(value as i128) + } +} + impl From for EncodedTerm { fn from(value: Decimal) -> Self { EncodedTerm::DecimalLiteral(value)