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

Fix bug in join algorithm in case of many empty blocks #1690

Open
wants to merge 3 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
4 changes: 3 additions & 1 deletion src/engine/Filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ ProtoResult Filter::computeResult(bool requestLaziness) {
for (auto& [idTable, localVocab] : subRes->idTables()) {
IdTable result = self->filterIdTable(subRes->sortedBy(),
idTable, localVocab);
co_yield {std::move(result), std::move(localVocab)};
if (!result.empty()) {
co_yield {std::move(result), std::move(localVocab)};
}
}
}(std::move(subRes), this),
resultSortedOn()};
Expand Down
4 changes: 4 additions & 0 deletions src/util/JoinAlgorithms/JoinAlgorithms.h
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,10 @@ struct BlockZipperJoinImpl {
for (size_t numBlocksRead = 0; it != end && numBlocksRead < 3;
++it, ++numBlocksRead) {
if (ql::ranges::empty(*it)) {
// We haven't read a block, so we have to adapt the counter.
// NOTE: If `numBlocksRead == 0`, the underflow is no problem because
// the next operation is `++`.
--numBlocksRead;
continue;
}
if (!eq((*it)[0], currentEl)) {
Expand Down
4 changes: 1 addition & 3 deletions test/FilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,11 @@ TEST(Filter, verifyPredicateIsAppliedCorrectlyOnLazyEvaluation) {
auto referenceTable1 =
makeIdTableFromVector({{true}, {true}, {true}}, asBool);
auto referenceTable2 = makeIdTableFromVector({{true}}, asBool);
IdTable referenceTable3{0, ad_utility::makeUnlimitedAllocator<Id>()};

auto m = matchesIdTable;
EXPECT_THAT(
toVector(std::move(generator)),
ElementsAre(m(referenceTable1), m(referenceTable2), m(referenceTable3),
m(referenceTable3), m(referenceTable2)));
ElementsAre(m(referenceTable1), m(referenceTable2), m(referenceTable2)));
}

// _____________________________________________________________________________
Expand Down
12 changes: 12 additions & 0 deletions test/JoinAlgorithmsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ TEST(JoinAlgorithms, JoinWithBlocksExactlyFourBlocksPerElement) {
testJoin(a, b, expectedResult);
}

// Test the handling of many empty blocks.
TEST(JoinAlgorithms, JoinWithEmptyBlocks) {
NestedBlock a{{{42, 1}, {42, 2}}, {{42, 3}}};
// The join has to handle all the entries with `42` in the first column at
// once. In `b` there are more than 3 empty blocks between blocks with this
// entry. There was previously a bug in this case.
NestedBlock b{{{42, 16}}, {}, {}, {}, {}, {}, {}, {}, {}, {{42, 23}}};
JoinResult expectedResult{{42, 1, 16}, {42, 1, 23}, {42, 2, 16},
{42, 2, 23}, {42, 3, 16}, {42, 3, 23}};
testJoin(a, b, expectedResult);
}

// ________________________________________________________________________________________
TEST(JoinAlgorithms, JoinWithBlocksMultipleBlocksPerElementBothSides) {
NestedBlock a{{{42, 0}}, {{42, 1}, {42, 2}}, {{42, 3}, {67, 0}}};
Expand Down
Loading