Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend PrefilterExpression (pre-filtering on metadata) for SPARQL expressions: isIri, isLiteral, isNumeric and isBlank. #1773

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions src/engine/sparqlExpressions/IsSomethingExpressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Chair of Algorithms and Data Structures.
// Author: Hannah Bast <[email protected]>

#include "engine/sparqlExpressions/LiteralExpression.h"
#include "engine/sparqlExpressions/NaryExpressionImpl.h"
#include "engine/sparqlExpressions/SparqlExpressionValueGetters.h"

Expand All @@ -23,18 +24,54 @@ namespace detail {
// `SparqlExpression::Ptr` and returns a `unique_ptr` to a new instance of
// `...Expression` (`std::move` the arguments into the constructor). The
// function should be declared in `NaryExpression.h`.
template <typename NaryOperation, prefilterExpressions::IsDatatype Datatype>
requires(isOperation<NaryOperation>)
class IsDatatypeExpressionImpl : public NaryExpression<NaryOperation> {
public:
using NaryExpression<NaryOperation>::NaryExpression;
std::vector<PrefilterExprVariablePair> getPrefilterExpressionForMetadata(
[[maybe_unused]] bool isNegated) const override {
using namespace prefilterExpressions;
std::vector<PrefilterExprVariablePair> prefilterVec;
const SparqlExpression* childExpr = this->getNthChild(0).value_or(nullptr);
// An IsSomethingExpression should always hold a child expression.
AD_CORRECTNESS_CHECK(childExpr != nullptr);
// Pre-filtering is only applicable if `isDatatype()` references a
// `VariableExpression` (e.g. `isLiteral(?x)`).
std::optional<Variable> optVar = childExpr->getVariableOrNullopt();
if (optVar.has_value()) {
prefilterVec.emplace_back(
std::make_unique<IsDatatypeExpression<Datatype>>(), optVar.value());
}
return prefilterVec;
}
};

//______________________________________________________________________________
// Expressions for the builtin functions `isIRI`, `isBlank`, `isLiteral`,
// `isNumeric`, and the custom function `isWktPoint`. Note that the value
// getters already return the correct `Id`, hence `std::identity`.
using isIriExpression = NARY<1, FV<std::identity, IsIriValueGetter>>;
using isLiteralExpression = NARY<1, FV<std::identity, IsLiteralValueGetter>>;
using isNumericExpression = NARY<1, FV<std::identity, IsNumericValueGetter>>;
template <typename Getter, prefilterExpressions::IsDatatype Datatype>
using IsDtypeExpression =
IsDatatypeExpressionImpl<Operation<1, FV<std::identity, Getter>>, Datatype>;

using isLiteralExpression =
IsDtypeExpression<IsLiteralValueGetter,
prefilterExpressions::IsDatatype::LITERAL>;
using isNumericExpression =
IsDtypeExpression<IsNumericValueGetter,
prefilterExpressions::IsDatatype::NUMERIC>;
using isBlankExpression =
NARY<1, FV<std::identity, IsValueIdValueGetter<Datatype::BlankNodeIndex>>>;
IsDtypeExpression<IsValueIdValueGetter<Datatype::BlankNodeIndex>,
prefilterExpressions::IsDatatype::BLANK>;
using isIriExpression =
IsDtypeExpression<IsIriValueGetter, prefilterExpressions::IsDatatype::IRI>;

// We currently don't support pre-filtering for `isGeoPointExpression`.
using isGeoPointExpression =
NARY<1, FV<std::identity, IsValueIdValueGetter<Datatype::GeoPoint>>>;

//______________________________________________________________________________
// The expression for `bound` is slightly different as `IsValidValueGetter`
// returns a `bool` and not an `Id`.
inline auto boolToId = [](bool b) { return Id::makeFromBool(b); };
Expand Down
Loading
Loading