-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor SPARQL expression definitions + add ABS, CEIL, FLOOR, ROUND (#…
…1043) 1. Refactor the code for the various SPARQL expressions and functions. The definitions are now in `.cpp` files, which reduces compile time. Each expression is defined in three parts: the actual behavior (e.g., `extractYear`), the corresponding type (e.g., `YearExpression` defined via the macro `NARY_EXPRESSION`), and the corresponding factory function that is used in the SPARQL parser (e.g., `makeYearExpression`). 2. Add the following four unary functions: `ABS`, `CEIL`, `FLOOR`, `ROUND`. Pay attention to the detail that according to the SPARQL standard, `ROUND` of negative numbers that lie exactly between two integers (e.g., `-42.5`) rounds towards zero (`-42`), unlike `std::round`, which rounds away from zero (`-43`).
- Loading branch information
Showing
18 changed files
with
881 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,10 @@ | ||
add_library(sparqlExpressions | ||
SparqlExpressionTypes.h | ||
SparqlExpression.h | ||
AggregateExpression.h | ||
GroupConcatExpression.h | ||
SparqlExpressionGenerators.h | ||
SparqlExpressionValueGetters.h SparqlExpressionValueGetters.cpp | ||
NaryExpression.h NaryExpression.cpp | ||
SetOfIntervals.h SetOfIntervals.cpp | ||
LiteralExpression.h GroupConcatExpression.h | ||
SparqlExpressionPimpl.h SparqlExpressionPimpl.cpp | ||
SampleExpression.h SampleExpression.cpp | ||
SparqlExpressionValueGetters.cpp | ||
NaryExpression.cpp | ||
SetOfIntervals.cpp | ||
SparqlExpressionPimpl.cpp | ||
SampleExpression.cpp | ||
RelationalExpressions.cpp AggregateExpression.cpp RegexExpression.cpp | ||
LangExpression.cpp) | ||
LangExpression.cpp NumericUnaryExpressions.cpp NumericBinaryExpressions.cpp DateExpressions.cpp StringExpressions.cpp) | ||
|
||
qlever_target_link_libraries(sparqlExpressions index) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2023, University of Freiburg, | ||
// Chair of Algorithms and Data Structures. | ||
// Author: Johannes Kalmbach <[email protected]> | ||
|
||
#include "engine/sparqlExpressions/NaryExpressionImpl.h" | ||
|
||
namespace sparqlExpression { | ||
namespace detail { | ||
// Date functions. | ||
// The input is `std::nullopt` if the argument to the expression is not a date. | ||
inline auto extractYear = [](std::optional<DateOrLargeYear> d) { | ||
if (!d.has_value()) { | ||
return Id::makeUndefined(); | ||
} else { | ||
return Id::makeFromInt(d->getYear()); | ||
} | ||
}; | ||
|
||
inline auto extractMonth = [](std::optional<DateOrLargeYear> d) { | ||
// TODO<C++23> Use the monadic operations for std::optional | ||
if (!d.has_value()) { | ||
return Id::makeUndefined(); | ||
} | ||
auto optionalMonth = d.value().getMonth(); | ||
if (!optionalMonth.has_value()) { | ||
return Id::makeUndefined(); | ||
} | ||
return Id::makeFromInt(optionalMonth.value()); | ||
}; | ||
|
||
inline auto extractDay = [](std::optional<DateOrLargeYear> d) { | ||
// TODO<C++23> Use the monadic operations for `std::optional`. | ||
if (!d.has_value()) { | ||
return Id::makeUndefined(); | ||
} | ||
auto optionalDay = d.value().getDay(); | ||
if (!optionalDay.has_value()) { | ||
return Id::makeUndefined(); | ||
} | ||
return Id::makeFromInt(optionalDay.value()); | ||
}; | ||
|
||
NARY_EXPRESSION(YearExpression, 1, FV<decltype(extractYear), DateValueGetter>); | ||
NARY_EXPRESSION(MonthExpression, 1, | ||
FV<decltype(extractMonth), DateValueGetter>); | ||
NARY_EXPRESSION(DayExpression, 1, FV<decltype(extractDay), DateValueGetter>); | ||
} // namespace detail | ||
using namespace detail; | ||
SparqlExpression::Ptr makeYearExpression(SparqlExpression::Ptr child) { | ||
return std::make_unique<YearExpression>(std::move(child)); | ||
} | ||
|
||
SparqlExpression::Ptr makeDayExpression(SparqlExpression::Ptr child) { | ||
return std::make_unique<DayExpression>(std::move(child)); | ||
} | ||
|
||
SparqlExpression::Ptr makeMonthExpression(SparqlExpression::Ptr child) { | ||
return std::make_unique<MonthExpression>(std::move(child)); | ||
} | ||
} // namespace sparqlExpression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.