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

Enable pre-filtering (using PrefilterExpressionIndex) of Date values over expression YEAR(). #1820

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

realHannes
Copy link
Collaborator

No description provided.

Copy link

codecov bot commented Feb 19, 2025

Codecov Report

Attention: Patch coverage is 86.84211% with 15 lines in your changes missing coverage. Please review.

Project coverage is 90.16%. Comparing base (8fe0642) to head (74b7d75).

Files with missing lines Patch % Lines
...ine/sparqlExpressions/PrefilterExpressionIndex.cpp 87.14% 1 Missing and 8 partials ⚠️
src/engine/sparqlExpressions/SparqlExpression.cpp 25.00% 3 Missing ⚠️
...engine/sparqlExpressions/RelationalExpressions.cpp 93.33% 0 Missing and 2 partials ⚠️
src/engine/sparqlExpressions/NaryExpressionImpl.h 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1820      +/-   ##
==========================================
- Coverage   90.18%   90.16%   -0.02%     
==========================================
  Files         400      400              
  Lines       38440    38509      +69     
  Branches     4306     4318      +12     
==========================================
+ Hits        34666    34722      +56     
- Misses       2479     2483       +4     
- Partials     1295     1304       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@realHannes realHannes requested a review from joka921 February 19, 2025 18:58
Copy link
Member

@joka921 joka921 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks very nice and clean, I only have a few remarks.

}
throw std::runtime_error(
"Pre-filtering DATETIME/DATE values over YEAR failed: requires "
"INTEGER reference value.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also output the illegal value that was passed, to make the error message more useful.

const auto* variableExpr = dynamic_cast<const VariableExpression*>(child0);
if (!variableExpr) {
return {};
const auto getOptVariableAndIsYear = [](const SparqlExpression* child)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a small comment about what this does.
And this lambda doesn't capture, so it can be a free function (less cluttering in the code).

Comment on lines +460 to +472
[&getOptVariableAndIsYear](
const SparqlExpression* child0, const SparqlExpression* child1,
bool reversed) -> std::vector<PrefilterExprVariablePair> {
if (auto optVariableIsYearPair = getOptVariableAndIsYear(child0);
optVariableIsYearPair) {
const auto& [variable, prefilterDate] = optVariableIsYearPair.value();
const auto& optReferenceValue =
detail::getIdOrLocalVocabEntryFromLiteralExpression(child1);
if (!optReferenceValue.has_value()) {
return {};
}
return prefilterExpressions::detail::makePrefilterExpressionVec<comp>(
optReferenceValue.value(), variable, reversed, prefilterDate);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simpler code flow:

auto opt1 = getOpVar(...);
if (! opt1) return {};
auto opt2 = getReferenceValue();
if (!opt2) return {};
// return the actual thing, but no double nested if statements in the code anymore

Comment on lines +70 to +71
[[maybe_unused]] size_t childIndex) const {
return std::nullopt;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have a virtual function children() which can be used here. The default of nullopt is really not necessary, but I think you can even make it non-virtual or final , because it directly relies on the correcteness of a function we already have.

Also, this function can easily be tested.

@@ -60,6 +60,13 @@ class SparqlExpression {
virtual std::unique_ptr<SparqlExpression> replaceChild(
size_t childIndex, std::unique_ptr<SparqlExpression> newExpression);

// Returns the child at index `childIndex` for this expression.
// By default the implementation of this method returns `std::nullopt`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, I don't like the default and don't think it's necessary.

@sparql-conformance
Copy link

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants