Skip to content

Commit

Permalink
refine comments + the required value-getter
Browse files Browse the repository at this point in the history
  • Loading branch information
realHannes committed Feb 20, 2025
1 parent 87a1b72 commit 5cb6897
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
26 changes: 12 additions & 14 deletions src/engine/sparqlExpressions/ConvertToDtypeConstructor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<DateYearOrDuration> optValue) {
if (optValue.has_value()) {
return Id::makeFromDate(optValue.value());
Expand All @@ -150,7 +148,7 @@ inline auto convertStringToDateTimeValueId =
};

if (auto* valueId = std::get_if<ValueId>(&inputValue)) {
return valueId->getDate().isDate() ? *valueId : Id::makeUndefined();
return *valueId;
}

auto* str = std::get_if<std::string>(&inputValue);
Expand Down
7 changes: 6 additions & 1 deletion src/engine/sparqlExpressions/SparqlExpressionValueGetters.h
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,12 @@ struct DateIdOrLiteralValueGetter : Mixin<DateIdOrLiteralValueGetter> {
// 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;

Check warning on line 369 in src/engine/sparqlExpressions/SparqlExpressionValueGetters.h

View check run for this annotation

Codecov / codecov/patch

src/engine/sparqlExpressions/SparqlExpressionValueGetters.h#L369

Added line #L369 was not covered by tests
}
return LiteralFromIdGetter{}(id, context);
}
Expand Down

0 comments on commit 5cb6897

Please sign in to comment.