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

Apply binary search filter expressions directly on the block metadata of Index Scans #1619

Merged
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
99da434
Added conversion str to int
realHannes Apr 25, 2024
424d023
templated function for toNumeric, add declaration to NaryExpression.h
realHannes Apr 25, 2024
0117e82
str to num for SparqlExpression implemented + added test
realHannes Apr 25, 2024
35fd0b1
Merge branch 'ad-freiburg:master' into master
realHannes Apr 26, 2024
94356c2
Update src/engine/sparqlExpressions/StringExpressions.cpp
realHannes Apr 26, 2024
decc8ba
Update src/engine/sparqlExpressions/StringExpressions.cpp
realHannes Apr 26, 2024
850152c
Update src/engine/sparqlExpressions/StringExpressions.cpp
realHannes Apr 26, 2024
d650d67
Update src/engine/sparqlExpressions/StringExpressions.cpp
realHannes Apr 26, 2024
46cc697
using now absl::from_chars() and stripping whitespaces for string to …
realHannes Apr 26, 2024
7fc5c28
added new functions to processIriFuntionCall() (for string to number)
realHannes Apr 26, 2024
efb0e24
renaming to: toIntExpression and toDoubleExpression for later more ge…
realHannes Apr 26, 2024
a88537c
made format (clang-format-16)
realHannes Apr 26, 2024
ca1e2e0
Update src/parser/sparqlParser/SparqlQleverVisitor.cpp
realHannes Apr 29, 2024
4adc831
Update src/parser/sparqlParser/SparqlQleverVisitor.cpp
realHannes Apr 29, 2024
d0f0d63
renaming in NaryExpression.h for accordance with other function, addi…
realHannes Apr 29, 2024
a118609
added test coverage for function calls makeIntExpression and make Dou…
realHannes Apr 29, 2024
062052e
toNumeric has now correct behavior and uses absl::from_chars() and st…
realHannes Apr 29, 2024
6d0f42a
made clang-format for NaryExpressionImpl.h
realHannes Apr 29, 2024
f90b8e2
Merge branch 'ad-freiburg:master' into master
realHannes May 6, 2024
fb88493
Merge branch 'ad-freiburg:master' into master
realHannes May 15, 2024
b2eb514
Merge remote-tracking branch 'upstream/master'
realHannes May 16, 2024
b165ac1
Merge branch 'ad-freiburg:master' into master
realHannes Jun 1, 2024
7a3dfb2
Merge branch 'master' of https://github.com/realHannes/qlever
realHannes Jun 1, 2024
fc0ad3a
Merge branch 'ad-freiburg:master' into master
realHannes Jun 6, 2024
f3e6086
Merge branch 'ad-freiburg:master' into master
realHannes Jun 7, 2024
fd4c351
Merge branch 'ad-freiburg:master' into master
realHannes Jun 10, 2024
220c9bf
Merge branch 'ad-freiburg:master' into master
realHannes Jun 12, 2024
a81cb8a
Merge branch 'ad-freiburg:master' into master
realHannes Jun 13, 2024
acc0109
Merge branch 'ad-freiburg:master' into master
realHannes Jun 14, 2024
cb8e560
Merge branch 'ad-freiburg:master' into master
realHannes Jun 20, 2024
2b39970
Merge branch 'ad-freiburg:master' into master
realHannes Jun 28, 2024
a0101e4
Merge branch 'ad-freiburg:master' into master
realHannes Jun 30, 2024
47dee1d
Merge branch 'ad-freiburg:master' into master
realHannes Sep 4, 2024
a8625f9
Merge branch 'ad-freiburg:master' into master
realHannes Sep 9, 2024
7f95069
Merge branch 'ad-freiburg:master' into master
realHannes Sep 12, 2024
28b8a69
Merge branch 'ad-freiburg:master' into master
realHannes Sep 13, 2024
7bb6e01
Merge branch 'ad-freiburg:master' into master
realHannes Sep 14, 2024
edc974a
Add implementation for pre-filtering blocks on their metadata
realHannes Sep 18, 2024
ca6c2ff
Merge branch 'master' into prefilter_on_metadata_relational
realHannes Sep 18, 2024
46be51a
fix spelling error
realHannes Sep 18, 2024
0385b56
add namespace for CompressedBlockPrefiltering.h
realHannes Sep 18, 2024
5707338
use std::ranges::set_union, std::ranges::upper_bound/lower_bound
realHannes Sep 18, 2024
c9687ec
move template specializations into namespace prefilterExpressions
realHannes Sep 18, 2024
d8246f7
fix
realHannes Sep 18, 2024
66b4872
hopefully fix namespace issue
realHannes Sep 18, 2024
e4eddc4
Merge branch 'ad-freiburg:master' into prefilter_on_metadata_relational
realHannes Sep 20, 2024
b5d7dd7
first adaptations regarding the comments
realHannes Sep 20, 2024
802e3aa
Merge branch 'ad-freiburg:master' into prefilter_on_metadata_relational
realHannes Sep 23, 2024
662b1d4
applied suggestions from review
realHannes Sep 24, 2024
510aa9e
fix std::move
realHannes Sep 24, 2024
0d7f75b
Merge branch 'ad-freiburg:master' into prefilter_on_metadata_relational
realHannes Sep 25, 2024
c119200
adjusted CompressedBlockPrefiltering
realHannes Sep 26, 2024
af17181
mark method with override
realHannes Sep 26, 2024
3d7238d
Merge branch 'master' into prefilter_on_metadata_relational
realHannes Oct 8, 2024
5af6138
make further changes to prefiltering procedure and its tests
realHannes Oct 8, 2024
b02dc57
add additional testing on IDs from other datatypes
realHannes Oct 8, 2024
eb86f1b
addition to test Not Expression with And and Or
realHannes Oct 8, 2024
69ed019
changes to test and fix index check fail
realHannes Oct 9, 2024
854322b
increase test coverage for Not expression
realHannes Oct 9, 2024
b2aa689
just add all mixed blocks
realHannes Oct 9, 2024
546c3b3
Merge branch 'ad-freiburg:master' into prefilter_on_metadata_relational
realHannes Oct 9, 2024
7e61cb1
remove unnecessary values in test context
realHannes Oct 9, 2024
009ebed
for sonar check
realHannes Oct 10, 2024
6c19bf6
Merge branch 'ad-freiburg:master' into prefilter_on_metadata_relational
realHannes Oct 10, 2024
bf733ce
Merge branch 'ad-freiburg:master' into environment_for_using_prefilte…
realHannes Oct 12, 2024
5b42c1f
methods to get PrefilterExpresssions from RelationalExpressions (Spar…
realHannes Oct 12, 2024
6cf6609
Completed the implementation for constructing PrefilterExpressions fr…
realHannes Oct 22, 2024
18c4c84
Merge branch 'master' into environment_for_using_prefiltering
realHannes Oct 22, 2024
e4be1fe
all builds should compile now
realHannes Oct 22, 2024
bde09cd
Merge branch 'ad-freiburg:master' into environment_for_using_prefilte…
realHannes Oct 22, 2024
74756fe
fix build issue and increase test coverage
realHannes Oct 22, 2024
1278d39
Merge branch 'master' into environment_for_using_prefiltering
realHannes Oct 22, 2024
47d3d56
Merge branch 'ad-freiburg:master' into environment_for_using_prefilte…
realHannes Oct 25, 2024
49de4d0
introduce test structure from PR1 (#1503)
realHannes Oct 25, 2024
fcefdf0
Merge branch 'master' into environment_for_using_prefiltering
realHannes Oct 28, 2024
9f0efc6
fix build
realHannes Oct 28, 2024
25f325a
implement proposed changes (2)
realHannes Oct 30, 2024
d65acc3
correction for codespell check
realHannes Oct 30, 2024
f85a96f
fix for codespell
realHannes Oct 30, 2024
0a188a5
Merge branch 'ad-freiburg:master' into environment_for_using_prefilte…
realHannes Oct 31, 2024
5f4e586
remove optionality (std::optional) for return value
realHannes Oct 31, 2024
8062753
Merge branch 'ad-freiburg:master' into environment_for_using_prefilte…
realHannes Nov 4, 2024
c06de60
implement proposed improvements (4)
realHannes Nov 4, 2024
95e9027
further adjustments + apply PrefilterExpressions in IndexScan
realHannes Nov 11, 2024
0992fab
Merge branch 'master' into environment_for_using_prefiltering
realHannes Nov 11, 2024
f489b24
few additional adaptations
realHannes Nov 11, 2024
1340021
Make `CartesianProductJoin` lazy. (#1609)
RobinTF Nov 13, 2024
23cea27
Get `PrefilterExpression` from `SparqlExpression` (#1613)
realHannes Nov 14, 2024
5144b47
Add STDEV() aggregate function (#1614)
ullingerc Nov 14, 2024
e9e6f8d
Merge located triples when performing index scans (#1597)
joka921 Nov 14, 2024
96ded86
Merge branch 'master' into implement-apply-prefilter-expressions
realHannes Nov 15, 2024
45cc1b4
changes w.r.t. comments from #1573
realHannes Nov 18, 2024
0a3f67e
Merge branch 'ad-freiburg:master' into implement-apply-prefilter-expr…
realHannes Nov 19, 2024
0b30ad3
updates from code review (1)
realHannes Nov 20, 2024
4bf0d01
Merge branch 'ad-freiburg:master' into implement-apply-prefilter-expr…
realHannes Nov 20, 2024
54c00ad
first empty prefilter scan fix
realHannes Nov 21, 2024
118ad87
Fix the bug that always disables prefilter expressions.
joka921 Nov 21, 2024
f47cc2c
Merge branch 'ad-freiburg:master' into implement-apply-prefilter-expr…
realHannes Nov 21, 2024
61a15ce
select only Variable for first column index + extend constructor
realHannes Nov 21, 2024
6ef031b
set multiplicities in IndexScan constructor
realHannes Nov 21, 2024
bef8211
changes for review (1)
realHannes Nov 23, 2024
80d54df
changes for review (2)
realHannes Nov 24, 2024
25eb418
correction for Codespell
realHannes Nov 24, 2024
83f2363
add testing
realHannes Nov 27, 2024
097e206
Merge branch 'master' into implement-apply-prefilter-expressions
realHannes Nov 27, 2024
1574860
FilterTest fix + codespell fix
realHannes Nov 27, 2024
9de745a
simplify test in IndexScanTest
realHannes Nov 27, 2024
0a7672c
more changes
realHannes Nov 28, 2024
0ff8689
test
realHannes Nov 28, 2024
bef9326
Merge branch 'master' into implement-apply-prefilter-expressions
realHannes Nov 29, 2024
6e54939
fix test error
realHannes Nov 29, 2024
2751fe1
adapt code part merge conflict
realHannes Nov 29, 2024
a884e39
Merge branch 'master' into implement-apply-prefilter-expressions
realHannes Nov 30, 2024
d5ad1ba
use std::move + adjust test for this PR
realHannes Nov 30, 2024
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
4 changes: 2 additions & 2 deletions src/engine/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ string Filter::getDescriptor() const {
void Filter::setPrefilterExpressionForChildren() {
std::vector<PrefilterVariablePair> prefilterPairs =
_expression.getPrefilterExpressionForMetadata();
auto optNewSubTree = _subtree->setPrefilterGetUpdatedQueryExecutionTree(
std::move(prefilterPairs));
auto optNewSubTree =
_subtree->setPrefilterGetUpdatedQueryExecutionTree(prefilterPairs);
if (optNewSubTree.has_value()) {
_subtree = std::move(optNewSubTree.value());
}
Expand Down
8 changes: 4 additions & 4 deletions src/engine/Filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ class Filter : public Operation {

// The method is directly invoked with the construction of this `Filter`
// object. Its implementation retrieves <PrefilterExpression, Variable> pairs
// from the corresponding `SparqlExpression` and calls
// `QueryExecutionTree::setPrefilterGetUpdatedQueryExecutionTree()` on those
// pair values. If necessary the `QueryExecutionTree` for this entity will be
// updated.
// from the corresponding `SparqlExpression` and uses them to call
// `QueryExecutionTree::setPrefilterGetUpdatedQueryExecutionTree()` on the
// `subtree_`. If necessary the `QueryExecutionTree` for this
// entity will be updated.
void setPrefilterExpressionForChildren();

ProtoResult computeResult(bool requestLaziness) override;
Expand Down
16 changes: 11 additions & 5 deletions src/engine/IndexScan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@
// _____________________________________________________________________________
std::optional<std::shared_ptr<QueryExecutionTree>>
IndexScan::setPrefilterGetUpdatedQueryExecutionTree(
std::vector<PrefilterVariablePair> prefilterVariablePairs) {
const std::vector<PrefilterVariablePair>& prefilterVariablePairs) const {
auto optSortedVarColIdxPair =
getSortedVariableAndMetadataColumnIndexForPrefiltering();
if (!optSortedVarColIdxPair.has_value()) {
return std::nullopt;
}

Check warning on line 165 in src/engine/IndexScan.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/IndexScan.cpp#L164-L165

Added lines #L164 - L165 were not covered by tests
const auto& [sortedVar, colIdx] = optSortedVarColIdxPair.value();
auto it =
std::ranges::find(prefilterVariablePairs, sortedVar, ad_utility::second);
Expand Down Expand Up @@ -315,8 +315,8 @@
std::optional<std::pair<Variable, ColumnIndex>>
IndexScan::getSortedVariableAndMetadataColumnIndexForPrefiltering() const {
if (numVariables_ < 1) {
return std::nullopt;
}

Check warning on line 319 in src/engine/IndexScan.cpp

View check run for this annotation

Codecov / codecov/patch

src/engine/IndexScan.cpp#L318-L319

Added lines #L318 - L319 were not covered by tests
const auto& permutedTriple = getPermutedTriple();
size_t colIdx = 3 - numVariables_;
const auto& tripleComp = permutedTriple.at(colIdx);
Expand All @@ -342,15 +342,15 @@
if (optBlockSpan.has_value()) {
const auto& blockSpan = optBlockSpan.value();
optBlocks = {blockSpan.begin(), blockSpan.end()};
applyPefilterIfPossible(optBlocks.value());
applyPrefilterIfPossible(optBlocks.value());
}
return optBlocks;
}

// _____________________________________________________________________________
void IndexScan::applyPefilterIfPossible(
void IndexScan::applyPrefilterIfPossible(
std::vector<CompressedBlockMetadata>& blocks) const {
if (prefilter_.has_value() && getLimit().isUnconstrained()) {
if (prefilter_.has_value()) {
// Apply the prefilter on given blocks.
auto& [prefilterExpr, columnIndex] = prefilter_.value();
blocks = prefilterExpr->evaluate(blocks, columnIndex);
Expand All @@ -360,14 +360,20 @@
// _____________________________________________________________________________
Permutation::IdTableGenerator IndexScan::getLazyScan(
std::vector<CompressedBlockMetadata> blocks) const {
applyPefilterIfPossible(blocks);
// If there is a LIMIT or OFFSET clause that constrains the scan
// (which can happen with an explicit subquery), we cannot use the prefiltered
// blocks, as we currently have no mechanism to include limits and offsets
// into the prefiltering (`std::nullopt` means `scan all blocks`).
auto filteredBlocks = getLimit().isUnconstrained()
? std::optional(std::move(blocks))
: std::nullopt;
if (filteredBlocks.has_value()) {
// Note: The prefilter expression applied with applyPrefilterIfPossible()
// is not related to the prefilter procedure mentioned in the comment above.
// If this IndexScan owns a <PrefilterExpression, ColumnIdx> pair, it can
// be applied.
applyPrefilterIfPossible(filteredBlocks.value());
realHannes marked this conversation as resolved.
Show resolved Hide resolved
}
return getScanPermutation().lazyScan(getScanSpecification(), filteredBlocks,
additionalColumns(), cancellationHandle_,
locatedTriplesSnapshot(), getLimit());
Expand Down
5 changes: 3 additions & 2 deletions src/engine/IndexScan.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ class IndexScan final : public Operation {
// if necessary.
std::optional<std::shared_ptr<QueryExecutionTree>>
setPrefilterGetUpdatedQueryExecutionTree(
std::vector<PrefilterVariablePair> prefilterVariablePairs) override;
const std::vector<PrefilterVariablePair>& prefilterVariablePairs)
const override;

size_t numVariables() const { return numVariables_; }

Expand Down Expand Up @@ -195,7 +196,7 @@ class IndexScan final : public Operation {
// If `isUnconstrained()` yields true, return the blocks as given or the
// prefiltered blocks (if `prefilter_` has value). If `isUnconstrained()` is
// false, return `std::nullopt`.
void applyPefilterIfPossible(
void applyPrefilterIfPossible(
std::vector<CompressedBlockMetadata>& blocks) const;

// Helper functions for the public `getLazyScanFor...` methods and
Expand Down
3 changes: 2 additions & 1 deletion src/engine/Operation.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class Operation {
// `IndexScan` in their subtree.
virtual std::optional<std::shared_ptr<QueryExecutionTree>>
setPrefilterGetUpdatedQueryExecutionTree(
[[maybe_unused]] std::vector<PrefilterVariablePair> prefilterPairs) {
[[maybe_unused]] const std::vector<PrefilterVariablePair>& prefilterPairs)
const {
return std::nullopt;
};

Expand Down
4 changes: 2 additions & 2 deletions src/engine/QueryExecutionTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ size_t QueryExecutionTree::getSizeEstimate() {
//_____________________________________________________________________________
std::optional<std::shared_ptr<QueryExecutionTree>>
QueryExecutionTree::setPrefilterGetUpdatedQueryExecutionTree(
std::vector<Operation::PrefilterVariablePair> prefilterPairs) const {
std::vector<Operation::PrefilterVariablePair>& prefilterPairs) const {
AD_CONTRACT_CHECK(rootOperation_);
VariableToColumnMap varToColMap = getVariableColumns();
realHannes marked this conversation as resolved.
Show resolved Hide resolved
std::erase_if(prefilterPairs, [&varToColMap](const auto& pair) {
Expand All @@ -118,7 +118,7 @@ QueryExecutionTree::setPrefilterGetUpdatedQueryExecutionTree(
return std::nullopt;
} else {
return rootOperation_->setPrefilterGetUpdatedQueryExecutionTree(
std::move(prefilterPairs));
prefilterPairs);
realHannes marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/engine/QueryExecutionTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class QueryExecutionTree {
// the corresponding `Variable` is visible in the `VariableToColumnMap`.
std::optional<std::shared_ptr<QueryExecutionTree>>
setPrefilterGetUpdatedQueryExecutionTree(
std::vector<Operation::PrefilterVariablePair> prefilterPairs) const;
std::vector<Operation::PrefilterVariablePair>& prefilterPairs) const;
realHannes marked this conversation as resolved.
Show resolved Hide resolved

size_t getDistinctEstimate(size_t col) const {
return static_cast<size_t>(rootOperation_->getSizeEstimate() /
Expand Down
21 changes: 15 additions & 6 deletions src/index/Permutation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,12 @@ IdTable Permutation::scan(
const auto& p = getActualPermutation(scanSpec);

return p.reader().scan(
scanSpec, blocks.has_value() ? blocks.value() : p.meta_.blockData(),
scanSpec,
blocks.has_value()
? blocks.value()
: p.getAugmentedMetadataForPermutation(locatedTriplesSnapshot),
additionalColumns, cancellationHandle,
getLocatedTriplesForPermutation(locatedTriplesSnapshot), limitOffset);
p.getLocatedTriplesForPermutation(locatedTriplesSnapshot), limitOffset);
}

// _____________________________________________________________________
Expand All @@ -79,8 +82,11 @@ size_t Permutation::getResultSizeOfScan(
std::optional<std::vector<CompressedBlockMetadata>> blocks) const {
const auto& p = getActualPermutation(scanSpec);
return p.reader().getResultSizeOfScan(
scanSpec, blocks.has_value() ? blocks.value() : p.meta_.blockData(),
getLocatedTriplesForPermutation(locatedTriplesSnapshot));
scanSpec,
blocks.has_value()
? blocks.value()
: p.getAugmentedMetadataForPermutation(locatedTriplesSnapshot),
p.getLocatedTriplesForPermutation(locatedTriplesSnapshot));
}

// _____________________________________________________________________
Expand All @@ -90,8 +96,11 @@ std::pair<size_t, size_t> Permutation::getSizeEstimateForScan(
std::optional<std::vector<CompressedBlockMetadata>> blocks) const {
const auto& p = getActualPermutation(scanSpec);
return p.reader().getSizeEstimateForScan(
scanSpec, blocks.has_value() ? blocks.value() : p.meta_.blockData(),
getLocatedTriplesForPermutation(locatedTriplesSnapshot));
scanSpec,
blocks.has_value()
? blocks.value()
: p.getAugmentedMetadataForPermutation(locatedTriplesSnapshot),
p.getLocatedTriplesForPermutation(locatedTriplesSnapshot));
}

// ____________________________________________________________________________
Expand Down
53 changes: 26 additions & 27 deletions test/engine/IndexScanTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,12 @@ void testLazyScanWithColumnThrows(
const auto testSetAndMakeScanWithPrefilterExpr =
[](const std::string& kg, const SparqlTriple& triple,
const Permutation::Enum permutation, IndexScan::PrefilterVariablePair pr,
const IdTable& idTableWithExpectedColumn, bool prefilterCanBeSet = true,
const std::vector<ValueId>& expectedIdsOnFilterColumn,
bool prefilterCanBeSet = true,
source_location l = source_location::current()) {
auto t = generateLocationTrace(l);
IndexScan scan{getQec(kg), permutation, triple};
auto variable = pr.second;
auto optUpdatedQet = scan.setPrefilterGetUpdatedQueryExecutionTree(
makeFilterExpression::filterHelper::makePrefilterVec(std::move(pr)));
if (optUpdatedQet.has_value()) {
Expand All @@ -194,15 +196,15 @@ const auto testSetAndMakeScanWithPrefilterExpr =
// Check that the prefiltering procedure yields the correct result given
// that the <PrefilterExpression, Variable> pair is correctly assigned
// to the IndexScan.
const IdTable& idTableFiltered = updatedQet->getRootOperation()
->computeResultOnlyForTesting()
.idTable();
auto isColumnIdSpan = idTableFiltered.getColumn(0);
auto expectedColumnIdSpan = idTableWithExpectedColumn.getColumn(0);
IdTable idTableFiltered = updatedQet->getRootOperation()
->computeResultOnlyForTesting()
.idTable()
.clone();
auto isColumnIdSpan =
idTableFiltered.getColumn(updatedQet->getVariableColumn(variable));
ASSERT_EQ(
(std::vector<Id>{isColumnIdSpan.begin(), isColumnIdSpan.end()}),
(std::vector<Id>{expectedColumnIdSpan.begin(),
expectedColumnIdSpan.end()}));
expectedIdsOnFilterColumn);
} else {
// Check our prediction that the prefilter with the given
// <PrefilterExpression, Variable> pair is not applicable (no updated
Expand Down Expand Up @@ -695,7 +697,7 @@ TEST(IndexScan, SetPrefilterVariablePairAndCheckCacheKey) {
TEST(IndexScan, checkEvaluationWithPrefiltering) {
using namespace makeFilterExpression;
using namespace filterHelper;
using I = TripleComponent::Iri;
auto I = ad_utility::testing::IntId;
std::string kg =
"<P1> <price_tag> 10 . <P2> <price_tag> 12 . <P3> <price_tag> "
"18 . <P4> <price_tag> 22 . <P5> <price_tag> 25 . <P6> "
Expand All @@ -706,57 +708,54 @@ TEST(IndexScan, checkEvaluationWithPrefiltering) {

// For the following tests, the <PrefilterExpression, Variable> pair is set
// and applied for the respective IndexScan.
testSetAndMakeScanWithPrefilterExpr(
kg, triple, Permutation::POS, pr(ge(IntId(10)), Variable{"?price"}),
makeIdTableFromVector(
{{10}, {12}, {18}, {22}, {25}, {147}, {174}, {174}, {189}, {194}},
IntId));
testSetAndMakeScanWithPrefilterExpr(kg, triple, Permutation::POS,
pr(ge(IntId(10)), Variable{"?price"}),
{I(10), I(12), I(18), I(22), I(25),
I(147), I(174), I(174), I(189), I(194)});
testSetAndMakeScanWithPrefilterExpr(
kg, triple, Permutation::POS,
pr(lt(DoubleId(147.32)), Variable{"?price"}),
makeIdTableFromVector({{10}, {12}, {18}, {22}, {25}, {147}}, IntId));
{I(10), I(12), I(18), I(22), I(25), I(147)});
testSetAndMakeScanWithPrefilterExpr(
kg, triple, Permutation::POS,
pr(andExpr(gt(DoubleId(12.00)), le(IntId(174))), Variable{"?price"}),
makeIdTableFromVector({{18}, {22}, {25}, {147}, {174}, {174}}, IntId));
{I(18), I(22), I(25), I(147), I(174), I(174)});

// For the following test, the Variable value doesn't match any of the scan
// triple Variable values. We expect that the prefilter is not applicable (=>
// set bool flag to false).
testSetAndMakeScanWithPrefilterExpr(
kg, triple, Permutation::POS,
pr(andExpr(gt(DoubleId(12.00)), le(IntId(174))), Variable{"?y"}),
makeIdTableFromVector({{0}}, IntId), false);
pr(andExpr(gt(DoubleId(12.00)), le(IntId(174))), Variable{"?y"}), {},
false);

// For the following tests, the first sorted column given the permutation
// doesn't match with the corresponding column for the Variable of the
// <PrefilterExpression, Variable> pair. We expect that the provided prefilter
// is not applicable (and can't be set).
testSetAndMakeScanWithPrefilterExpr(
kg, triple, Permutation::PSO,
pr(andExpr(gt(DoubleId(12.00)), le(IntId(174))), Variable{"?price"}),
makeIdTableFromVector({{0}}, IntId), false);
pr(andExpr(gt(DoubleId(12.00)), le(IntId(174))), Variable{"?price"}), {},
false);
testSetAndMakeScanWithPrefilterExpr(
kg, triple, Permutation::POS,
pr(andExpr(gt(VocabId(0)), lt(VocabId(100))), Variable{"?x"}),
makeIdTableFromVector({{0}}, IntId), false);
pr(andExpr(gt(VocabId(0)), lt(VocabId(100))), Variable{"?x"}), {}, false);

// This knowledge graph yields an incomplete first and last block.
std::string kgFirstAndLastIncomplete =
"<a> <price_tag> 10 . <b> <price_tag> 12 . <b> <price_tag> "
"18 . <b> <price_tag> 22 . <b> <price_tag> 25 . <b> "
"<price_tag> 147 . <b> <price_tag> 189 . <c> <price_tag> 194 "
".";
triple = {I::fromIriref("<b>"), "<price_tag>", Tc{Variable{"?price"}}};
// The following test verifies that the prefilter procedure is successfully
// applicable under the condition that the first and last block are
// potentially incomplete.
testSetAndMakeScanWithPrefilterExpr(
kgFirstAndLastIncomplete, triple, Permutation::PSO,
kgFirstAndLastIncomplete, triple, Permutation::POS,
pr(orExpr(gt(IntId(100)), le(IntId(10))), Variable{"?price"}),
makeIdTableFromVector({{12}, {25}, {147}, {189}}, IntId));
{I(10), I(12), I(25), I(147), I(189), I(194)});
testSetAndMakeScanWithPrefilterExpr(
kgFirstAndLastIncomplete, triple, Permutation::SPO,
kgFirstAndLastIncomplete, triple, Permutation::POS,
pr(andExpr(gt(IntId(10)), lt(IntId(194))), Variable{"?price"}),
makeIdTableFromVector({{12}, {18}, {22}, {25}, {147}, {189}}, IntId));
{I(10), I(12), I(18), I(22), I(25), I(147), I(189), I(194)});
}
Loading