SPARQL: adds YEAR/.../SECONDS functions

pull/10/head
Tpt 6 years ago
parent 8de71d4536
commit a77d08cf03
  1. 36
      lib/src/sparql/eval.rs
  2. 29
      lib/src/sparql/plan.rs
  3. 12
      lib/src/store/numeric_encoder.rs

@ -483,6 +483,42 @@ impl<S: EncodedQuadsStore> SimpleEvaluator<S> {
},
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

@ -206,14 +206,15 @@ pub enum PlanExpression {
StrStarts(Box<PlanExpression>, Box<PlanExpression>),
StrEnds(Box<PlanExpression>, Box<PlanExpression>),
StrBefore(Box<PlanExpression>, Box<PlanExpression>),
StrAfter(Box<PlanExpression>, Box<PlanExpression>),
StrAfter(Box<PlanExpression>, Box<PlanExpression>),*/
Year(Box<PlanExpression>),
Month(Box<PlanExpression>),
Day(Box<PlanExpression>),
Hours(Box<PlanExpression>),
Minutes(Box<PlanExpression>),
Seconds(Box<PlanExpression>),
Timezone(Box<PlanExpression>),
/*Timezone(Box<PlanExpression>),
Tz(Box<PlanExpression>),
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) => {

@ -298,6 +298,18 @@ impl From<f64> for EncodedTerm {
}
}
impl From<i32> for EncodedTerm {
fn from(value: i32) -> Self {
EncodedTerm::IntegerLiteral(value as i128)
}
}
impl From<u32> for EncodedTerm {
fn from(value: u32) -> Self {
EncodedTerm::IntegerLiteral(value as i128)
}
}
impl From<Decimal> for EncodedTerm {
fn from(value: Decimal) -> Self {
EncodedTerm::DecimalLiteral(value)

Loading…
Cancel
Save