Skip to content

Commit

Permalink
Add unit tests and update a lot of things.
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Kalmbach <[email protected]>
  • Loading branch information
joka921 committed Nov 27, 2024
1 parent 957e44a commit 43f7d4f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 18 deletions.
21 changes: 11 additions & 10 deletions src/index/LocatedTriples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,22 +251,21 @@ void LocatedTriplesPerBlock::setOriginalMetadata(
updateAugmentedMetadata();
}

// Update the `blockMetadata`, such that its metadata pertaining to the
// contained graphs is consistent with the `locatedTriples` which are added to
// that block. In particular, all graphs to which at least one triple is added
// is added to the graph metadata, and if the number of total graphs is larger
// than the configured threshold, then the graph metadata is set to `nullopt`,
// which means that there is no metadata.
// Update the `blockMetadata`, such that its graph info is consistent with the
// `locatedTriples` which are added to that block. In particular, all graphs to
// which at least one triple is inserted become part of the graph info, and if
// the number of total graphs becomes larger than the configured threshold, then
// the graph info is set to `nullopt`, which means that there is no info.
static auto updateGraphMetadata(CompressedBlockMetadata& blockMetadata,
const LocatedTriples& locatedTriples) {
// We do not know anything about the triples contained in the block, so we
// also Cannot know if the `locatedTriples` introduces duplicates. We thus
// also cannot know if the `locatedTriples` introduces duplicates. We thus
// have to be conservative and assume that there are duplicates.
blockMetadata.containsDuplicatesWithDifferentGraphs_ = true;
auto& graphs = blockMetadata.graphInfo_;
if (!graphs.has_value()) {
// The original block already contains too many graphs, don't store any
// metadata.
// graph info.
return;
}

Expand All @@ -281,14 +280,16 @@ static auto updateGraphMetadata(CompressedBlockMetadata& blockMetadata,
}
newGraphs.insert(lt.triple_.ids_.at(ADDITIONAL_COLUMN_GRAPH_ID));
// Handle the case that with the newly added triples we have too many
// distinct graphs to store them in the metadata.
// distinct graphs to store them in the graph info.
if (newGraphs.size() > MAX_NUM_GRAPHS_STORED_IN_BLOCK_METADATA) {
graphs.reset();
return;
}
}
graphs.emplace(newGraphs.begin(), newGraphs.end());
// Sort the stored graphs, to make the testing easier.

// Sort the stored graphs. Note: this is currently not expected by the code
// that uses the graph info, but makes testing much easier.
std::ranges::sort(graphs.value());
}

Expand Down
20 changes: 18 additions & 2 deletions test/LocatedTriplesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,25 @@ TEST_F(LocatedTriplesTest, augmentedMetadataGraphInfo) {

// Note: the GraphInfo hasn't changed, because the new triples all were
// deleted.
auto m = locatedTriplesPerBlock.getAugmentedMetadata();
EXPECT_THAT(locatedTriplesPerBlock.getAugmentedMetadata(),
auto actualMetadata = locatedTriplesPerBlock.getAugmentedMetadata();
EXPECT_THAT(actualMetadata,
testing::ElementsAreArray(expectedAugmentedMetadata));

// Test the case that a block loses its graph info if the added located
// triples have too many distinct graphs.
ASSERT_TRUE(actualMetadata[1].graphInfo_.has_value());
std::vector<IdTriple<0>> triples;
for (size_t i = 30; i < 30 + 2 * MAX_NUM_GRAPHS_STORED_IN_BLOCK_METADATA;
++i) {
auto tr = T3;
tr.ids_.at(ADDITIONAL_COLUMN_GRAPH_ID) = V(i);
triples.push_back(tr);
}
// Add the located triples.
locatedTriplesPerBlock.add(LocatedTriple::locateTriplesInPermutation(
triples, metadata, {0, 1, 2}, true, handle));
actualMetadata = locatedTriplesPerBlock.getAugmentedMetadata();
ASSERT_FALSE(actualMetadata[1].graphInfo_.has_value());
}
}

Expand Down
23 changes: 17 additions & 6 deletions test/PrefilterExpressionIndexTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,32 @@ class PrefilterExpressionOnMetadataTest : public ::testing::Test {

//______________________________________________________________________________
TEST_F(PrefilterExpressionOnMetadataTest, testBlockFormatForDebugging) {
auto toString = [](const CompressedBlockMetadata& b) {
return (std::stringstream{} << b).str();
};

auto matcher = [&toString](const std::string& substring) {
return ::testing::ResultOf(toString, ::testing::HasSubstr(substring));
};
EXPECT_THAT(
(std::stringstream() << b5).str(),
::testing::HasSubstr(
b5,
matcher(
"#BlockMetadata\n(first) Triple: I:0 V:10 D:33.000000 V:0\n(last) "
"Triple: I:0 V:10 D:33.000000 V:0\nnum. rows: 0.\n"));
EXPECT_THAT(
(std::stringstream() << b11).str(),
::testing::HasSubstr(
b11,
matcher(
"#BlockMetadata\n(first) Triple: I:-4 V:10 D:33.000000 V:0\n(last) "
"Triple: D:2.000000 V:10 D:33.000000 V:0\nnum. rows: 0.\n"));
EXPECT_THAT(
(std::stringstream() << b21).str(),
::testing::HasSubstr(
b21,
matcher(
"#BlockMetadata\n(first) Triple: V:14 V:10 D:33.000000 V:0\n(last) "
"Triple: V:17 V:10 D:33.000000 V:0\nnum. rows: 0.\n"));

auto blockWithGraphInfo = b21;
blockWithGraphInfo.graphInfo_.emplace({IntId(12), IntId(13)});
EXPECT_THAT(blockWithGraphInfo, matcher("Graphs: I:12, I:13\n"));
}

// Test Relational Expressions
Expand Down

0 comments on commit 43f7d4f

Please sign in to comment.