Skip to content

Commit

Permalink
Fix the cache key of the DESCRIBE clause.
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Kalmbach <[email protected]>
  • Loading branch information
joka921 committed Nov 21, 2024
1 parent 72110b8 commit 71a1de6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/engine/Describe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,33 @@ std::vector<QueryExecutionTree*> Describe::getChildren() {
// _____________________________________________________________________________
string Describe::getCacheKeyImpl() const {
// The cache key must represent the `resources_` as well as the `subtree_`.
std::string resourceKey;
std::string result = absl::StrCat("DESCRIBE ", subtree_->getCacheKey(), " ");
for (const auto& resource : describe_.resources_) {
if (std::holds_alternative<TripleComponent::Iri>(resource)) {
resourceKey.append(
result.append(
std::get<TripleComponent::Iri>(resource).toStringRepresentation());
} else {
resourceKey.append(absl::StrCat(
result.append(absl::StrCat(
"column #",
subtree_->getVariableColumnOrNullopt(std::get<Variable>(resource))
.value_or(static_cast<size_t>(-1)),
" "));
}
}
return absl::StrCat("DESCRIBE ", subtree_->getCacheKey(), resourceKey);

const auto& defaultGraphs = describe_.datasetClauses_.defaultGraphs_;
if (defaultGraphs.has_value()) {
// The graphs are stored as a hash set, but we need a deterministic order.
std::vector<std::string> graphIdVec;
std::ranges::transform(defaultGraphs.value(),
std::back_inserter(graphIdVec),
&TripleComponent::toRdfLiteral);
std::ranges::sort(graphIdVec);
absl::StrAppend(&result,
"\nFiltered by Graphs:",
absl::StrJoin(graphIdVec, " "));
}
return result;
}

// _____________________________________________________________________________
Expand Down
14 changes: 13 additions & 1 deletion test/engine/DescribeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,19 @@ TEST(Describe, simpleMembers) {
using namespace ::testing;
EXPECT_THAT(describe.getCacheKey(),
AllOf(HasSubstr("DESCRIBE"), HasSubstr("<s>"),
Not(HasSubstr("<p>")), HasSubstr("Neutral Element")));
Not(HasSubstr("<p>")), HasSubstr("Neutral Element"), Not(HasSubstr("Filtered"))));
{
auto parsedDescribe2 = parsedDescribe;
parsedDescribe2.datasetClauses_.defaultGraphs_.emplace(
{TripleComponent::Iri::fromIriref("<default-graph-1>")});
Describe describe2{
qec, ad_utility::makeExecutionTree<NeutralElementOperation>(qec),
parsedDescribe2};
EXPECT_THAT(describe2.getCacheKey(),
AllOf(HasSubstr("DESCRIBE"), HasSubstr("<s>"),
Not(HasSubstr("<p>")), HasSubstr("Neutral Element"),
HasSubstr("Filtered by Graphs:<default-graph-1>")));
}

auto col = makeAlwaysDefinedColumn;
using V = Variable;
Expand Down

0 comments on commit 71a1de6

Please sign in to comment.