From 5cb68978953d1f3507c5b46b67991c89a60a5a81 Mon Sep 17 00:00:00 2001 From: realHannes Date: Thu, 20 Feb 2025 22:07:45 +0100 Subject: [PATCH] refine comments + the required value-getter --- .../ConvertToDtypeConstructor.cpp | 26 +++++++++---------- .../SparqlExpressionValueGetters.h | 7 ++++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/engine/sparqlExpressions/ConvertToDtypeConstructor.cpp b/src/engine/sparqlExpressions/ConvertToDtypeConstructor.cpp index 15df4cad99..d8355d7e1d 100644 --- a/src/engine/sparqlExpressions/ConvertToDtypeConstructor.cpp +++ b/src/engine/sparqlExpressions/ConvertToDtypeConstructor.cpp @@ -8,21 +8,19 @@ #include "engine/sparqlExpressions/NaryExpressionImpl.h" /* - The SparqlExpressions specified in the following namespace sections enable - xsd:datatype casting/mapping for XML-schema-datatype values. + The SparqlExpressions specified in the following namespace sections + enable datatype casting/mapping for XML-schema-datatype values. For more details regarding the casting/mapping definition see: https://www.w3.org/TR/sparql11-query/#FunctionMapping EXAMPLES - (1) BIND(xsd:dateTime(?var) as ?dateTimeValue) will try to convert the - date-time provided (bound to ?var) as an xsd:string value to an actual - xsd:dateTime value and bind it to ?dateTimeValue under the condition the - string was appropriately formatted. - - (2) BIND(xsd:integer(?var) to ?integerValue) attempts to convert ?var to an - xsd:integer value and bind it to variable ?integerValue, given the datatype - casting can be successfully performed. + (1) `xsd:dateTime(?var)` attempts to convert the date-time provided in form of + a xsd:string value, which is bound to ?var, into an actual xsd:dateTime + datatype value. If the conversion fails, the result is `undefined`. + + (2) `xsd:integer(?var)` attempts to convert the value bound to ?var into an + xsd:integer. If the conversion fails, the result is `undefined`. */ namespace sparqlExpression { @@ -139,9 +137,9 @@ inline auto convertStringToDateTimeValueId = } const auto& inputValue = input.value(); - // Remark: If the parsing procedure for datetime / date string values with - // parseXsdDatetimeGetOptDate / parseXsdDateGetOptDate fails, - // Id::makeUndefined() is returned as well. + // Remark: If the parsing procedure for datetime/date string values with + // parseXsdDatetimeGetOptDate/parseXsdDateGetOptDate fails, + // return Id::makeUndefined(). const auto retrieveValueId = [](std::optional optValue) { if (optValue.has_value()) { return Id::makeFromDate(optValue.value()); @@ -150,7 +148,7 @@ inline auto convertStringToDateTimeValueId = }; if (auto* valueId = std::get_if(&inputValue)) { - return valueId->getDate().isDate() ? *valueId : Id::makeUndefined(); + return *valueId; } auto* str = std::get_if(&inputValue); diff --git a/src/engine/sparqlExpressions/SparqlExpressionValueGetters.h b/src/engine/sparqlExpressions/SparqlExpressionValueGetters.h index f675b62ca3..0aba47f3d4 100644 --- a/src/engine/sparqlExpressions/SparqlExpressionValueGetters.h +++ b/src/engine/sparqlExpressions/SparqlExpressionValueGetters.h @@ -361,7 +361,12 @@ struct DateIdOrLiteralValueGetter : Mixin { // contain date-related string values. OptIdOrString operator()(ValueId id, const EvaluationContext* context) const { if (id.getDatatype() == Datatype::Date) { - return id; + // Additionally check that `DateYearOrDuration` doesn't hold a + // `DayTimeDuration` value. + if (id.getDate().isDate()) { + return id; + } + return std::nullopt; } return LiteralFromIdGetter{}(id, context); }