Fixes MONTH() and DAY() function evaluation on xsd:date

pull/58/head
Tpt 4 years ago
parent fa068e1e53
commit 3ecaaf07c0
  1. 2
      CHANGELOG.md
  2. 16
      lib/src/model/xsd/date_time.rs
  3. 4
      lib/src/sparql/eval.rs
  4. 2
      testsuite/src/sparql_evaluator.rs

@ -3,6 +3,8 @@
### Added ### Added
- [SPARQL 1.1 Update](https://www.w3.org/TR/sparql11-update/) support for Rust, Python and JavaScript. - [SPARQL 1.1 Update](https://www.w3.org/TR/sparql11-update/) support for Rust, Python and JavaScript.
## Changed
- Fixes evaluation of `MONTH()` and `DAY()` functions on the `xsd:date` values.
## [0.1.1] - 2020-08-14 ## [0.1.1] - 2020-08-14

@ -142,7 +142,7 @@ impl DateTime {
} }
} }
/// [op:sub-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-sub-yearMonthDuration-from-dateTime) /// [op:subtract-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDuration-from-dateTime)
pub fn checked_sub_year_month_duration( pub fn checked_sub_year_month_duration(
&self, &self,
rhs: impl Into<YearMonthDuration>, rhs: impl Into<YearMonthDuration>,
@ -150,7 +150,7 @@ impl DateTime {
self.checked_sub_duration(Duration::from(rhs.into())) self.checked_sub_duration(Duration::from(rhs.into()))
} }
/// [op:sub-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-dateTime) /// [op:subtract-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-dateTime)
pub fn checked_sub_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> { pub fn checked_sub_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
Some(Self { Some(Self {
@ -158,7 +158,7 @@ impl DateTime {
}) })
} }
/// [op:sub-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-sub-yearMonthDuration-from-dateTime) and [op:sub-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-dateTime) /// [op:subtract-yearMonthDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDuration-from-dateTime) and [op:subtract-dayTimeDuration-from-dateTime](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-dateTime)
pub fn checked_sub_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_sub_duration(&self, rhs: impl Into<Duration>) -> Option<Self> {
let rhs = rhs.into(); let rhs = rhs.into();
if let Ok(rhs) = DayTimeDuration::try_from(rhs) { if let Ok(rhs) = DayTimeDuration::try_from(rhs) {
@ -314,12 +314,12 @@ impl Time {
.ok() .ok()
} }
/// [op:sub-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-time) /// [op:subtract-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-time)
pub fn checked_sub_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> { pub fn checked_sub_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> {
self.checked_sub_duration(Duration::from(rhs.into())) self.checked_sub_duration(Duration::from(rhs.into()))
} }
/// [op:sub-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-time) /// [op:subtract-dayTimeDuration-from-time](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-time)
pub fn checked_sub_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_sub_duration(&self, rhs: impl Into<Duration>) -> Option<Self> {
DateTime::new( DateTime::new(
1972, 1972,
@ -466,7 +466,7 @@ impl Date {
.ok() .ok()
} }
/// [op:sub-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-sub-yearMonthDuration-from-date) /// [op:subtract-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDuration-from-date)
pub fn checked_sub_year_month_duration( pub fn checked_sub_year_month_duration(
&self, &self,
rhs: impl Into<YearMonthDuration>, rhs: impl Into<YearMonthDuration>,
@ -474,12 +474,12 @@ impl Date {
self.checked_sub_duration(Duration::from(rhs.into())) self.checked_sub_duration(Duration::from(rhs.into()))
} }
/// [op:sub-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-date) /// [op:subtract-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-date)
pub fn checked_sub_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> { pub fn checked_sub_day_time_duration(&self, rhs: impl Into<DayTimeDuration>) -> Option<Self> {
self.checked_sub_duration(Duration::from(rhs.into())) self.checked_sub_duration(Duration::from(rhs.into()))
} }
/// [op:sub-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-sub-yearMonthDuration-from-date) and [op:sub-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-sub-dayTimeDuration-from-date) /// [op:subtract-yearMonthDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-subtract-yearMonthDuration-from-date) and [op:subtract-dayTimeDuration-from-date](https://www.w3.org/TR/xpath-functions/#func-subtract-dayTimeDuration-from-date)
pub fn checked_sub_duration(&self, rhs: impl Into<Duration>) -> Option<Self> { pub fn checked_sub_duration(&self, rhs: impl Into<Duration>) -> Option<Self> {
DateTime::try_from(*self) DateTime::try_from(*self)
.ok()? .ok()?

@ -1285,7 +1285,7 @@ where
}, },
PlanExpression::Month(e) => match self.eval_expression(e, tuple)? { PlanExpression::Month(e) => match self.eval_expression(e, tuple)? {
EncodedTerm::DateTimeLiteral(date_time) => Some(date_time.month().into()), EncodedTerm::DateTimeLiteral(date_time) => Some(date_time.month().into()),
EncodedTerm::DateLiteral(date) => Some(date.year().into()), EncodedTerm::DateLiteral(date) => Some(date.month().into()),
EncodedTerm::GYearMonthLiteral(year_month) => Some(year_month.month().into()), EncodedTerm::GYearMonthLiteral(year_month) => Some(year_month.month().into()),
EncodedTerm::GMonthDayLiteral(month_day) => Some(month_day.month().into()), EncodedTerm::GMonthDayLiteral(month_day) => Some(month_day.month().into()),
EncodedTerm::GMonthLiteral(month) => Some(month.month().into()), EncodedTerm::GMonthLiteral(month) => Some(month.month().into()),
@ -1293,7 +1293,7 @@ where
}, },
PlanExpression::Day(e) => match self.eval_expression(e, tuple)? { PlanExpression::Day(e) => match self.eval_expression(e, tuple)? {
EncodedTerm::DateTimeLiteral(date_time) => Some(date_time.day().into()), EncodedTerm::DateTimeLiteral(date_time) => Some(date_time.day().into()),
EncodedTerm::DateLiteral(date) => Some(date.year().into()), EncodedTerm::DateLiteral(date) => Some(date.day().into()),
EncodedTerm::GMonthDayLiteral(month_day) => Some(month_day.day().into()), EncodedTerm::GMonthDayLiteral(month_day) => Some(month_day.day().into()),
EncodedTerm::GDayLiteral(day) => Some(day.day().into()), EncodedTerm::GDayLiteral(day) => Some(day.day().into()),
_ => None, _ => None,

@ -114,8 +114,8 @@ fn evaluate_sparql_test(test: &Test) -> Result<()> {
} else { } else {
Err(anyhow!("Failure on {}.\nExpected file:\n{}\nOutput file:\n{}\nParsed query:\n{}\nData:\n{}\n", Err(anyhow!("Failure on {}.\nExpected file:\n{}\nOutput file:\n{}\nParsed query:\n{}\nData:\n{}\n",
test, test,
actual_results,
expected_results, expected_results,
actual_results,
Query::parse(&read_file_to_string(query_file)?, Some(query_file)).unwrap(), Query::parse(&read_file_to_string(query_file)?, Some(query_file)).unwrap(),
store store
)) ))

Loading…
Cancel
Save