Skip to content

Commit

Permalink
Merge branch 'ad-freiburg:master' into add-prefilter-is-datatype
Browse files Browse the repository at this point in the history
  • Loading branch information
realHannes authored Feb 12, 2025
2 parents b58cc0b + 2fad765 commit edf4378
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
13 changes: 8 additions & 5 deletions src/engine/ExportQueryExecutionTrees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,13 +749,10 @@ ad_utility::streams::stream_generator ExportQueryExecutionTrees::
co_yield absl::StrCat(R"({"head":{"vars":)", jsonVars.dump(),
R"(},"results":{"bindings":[)");

// Get all columns with defined variables.
QueryExecutionTree::ColumnIndicesAndTypes columns =
qet.selectedVariablesToColumnIndices(selectClause, false);
std::erase(columns, std::nullopt);
if (columns.empty()) {
co_yield "]}}";
co_return;
}

auto getBinding = [&](const IdTable& idTable, const uint64_t& i,
const LocalVocab& localVocab) {
Expand All @@ -773,6 +770,8 @@ ad_utility::streams::stream_generator ExportQueryExecutionTrees::
return binding.dump();
};

// Iterate over the result and yield the bindings. Note that when `columns`
// is empty, we have to output an empty set of bindings per row.
bool isFirstRow = true;
uint64_t resultSize = 0;
for (const auto& [pair, range] :
Expand All @@ -781,7 +780,11 @@ ad_utility::streams::stream_generator ExportQueryExecutionTrees::
if (!isFirstRow) [[likely]] {
co_yield ",";
}
co_yield getBinding(pair.idTable_, i, pair.localVocab_);
if (columns.empty()) {
co_yield "{}";
} else {
co_yield getBinding(pair.idTable_, i, pair.localVocab_);
}
cancellationHandle->throwIfCancelled();
isFirstRow = false;
}
Expand Down
20 changes: 13 additions & 7 deletions test/ExportQueryExecutionTreesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,14 @@ TEST(ExportQueryExecutionTrees, UnusedVariable) {
"\n"
"\n",
makeExpectedQLeverJSON({std::nullopt, std::nullopt}),
makeExpectedSparqlJSON({}), expectedXml};
[]() {
nlohmann::json j;
j["head"]["vars"].push_back("o");
j["results"]["bindings"].push_back({});
j["results"]["bindings"].push_back({});
return j;
}(),
expectedXml};
runSelectQueryTestCase(testCase);

// The `2` is the number of results including triples with UNDEF values. The
Expand Down Expand Up @@ -1061,8 +1068,7 @@ TEST(ExportQueryExecutionTrees, EmptyLines) {
[]() {
nlohmann::json j;
j["head"]["vars"] = nlohmann::json::array();
j["results"]["bindings"] =
nlohmann::json::array();
j["results"]["bindings"].push_back({});
return j;
}(),
expectedXml};
Expand Down Expand Up @@ -1257,13 +1263,13 @@ TEST(ExportQueryExecutionTrees, CornerCases) {
ad_utility::MediaType::octetStream),
ad_utility::Exception);

// A SparqlJSON query where none of the variables is even visible in the
// query body is not supported.
// If none of the selected variables is defined in the query body, we have an
// empty solution mapping per row, but there is no need to materialize any
// IRIs or literals.
std::string queryNoVariablesVisible = "SELECT ?not ?known WHERE {<s> ?p ?o}";
auto resultNoColumns = runJSONQuery(kg, queryNoVariablesVisible,
ad_utility::MediaType::sparqlJson);
ASSERT_TRUE(resultNoColumns["results"]["bindings"].empty());

ASSERT_EQ(resultNoColumns["results"]["bindings"].size(), 1);
auto qec = ad_utility::testing::getQec(kg);
AD_EXPECT_THROW_WITH_MESSAGE(
ExportQueryExecutionTrees::idToStringAndType(qec->getIndex(), Id::max(),
Expand Down

0 comments on commit edf4378

Please sign in to comment.