diff --git a/src/engine/ExportQueryExecutionTrees.cpp b/src/engine/ExportQueryExecutionTrees.cpp index 3913117016..873bd21ae7 100644 --- a/src/engine/ExportQueryExecutionTrees.cpp +++ b/src/engine/ExportQueryExecutionTrees.cpp @@ -626,13 +626,15 @@ ad_utility::streams::stream_generator ExportQueryExecutionTrees:: return binding.dump(); }; + bool isFirstRow = true; for (const auto& [idTable, range] : getRowIndices(limitAndOffset, *result)) { for (uint64_t i : range) { - if (i != 0) [[likely]] { + if (!isFirstRow) [[likely]] { co_yield ","; } co_yield getBinding(idTable, i); cancellationHandle->throwIfCancelled(); + isFirstRow = false; } } diff --git a/test/ExportQueryExecutionTreesTest.cpp b/test/ExportQueryExecutionTreesTest.cpp index ddef90a024..69c4e7d8dd 100644 --- a/test/ExportQueryExecutionTreesTest.cpp +++ b/test/ExportQueryExecutionTreesTest.cpp @@ -1053,6 +1053,53 @@ TEST(ExportQueryExecutionTrees, MultipleVariables) { runSelectQueryTestCase(testCaseMultipleVariables); } +// ____________________________________________________________________________ +TEST(ExportQueryExecutionTrees, LimitOffset) { + std::string kg = " . . . "; + std::string objectQuery = + "SELECT ?s WHERE { ?s ?p ?o } ORDER BY ?s LIMIT 2 OFFSET 1"; + std::string expectedXml = makeXMLHeader({"s"}) + + R"( + + d + + + g + )" + xmlTrailer; + TestCaseSelectQuery testCaseLimitOffset{ + kg, objectQuery, 2, + // TSV + "?s\n" + "\n" + "\n", + // CSV + "s\n" + "d\n" + "g\n", + []() { + nlohmann::json j; + j.push_back(std::vector{ + ""s, + }); + j.push_back(std::vector{ + ""s, + }); + return j; + }(), + []() { + nlohmann::json j; + j["head"]["vars"].push_back("s"); + auto& bindings = j["results"]["bindings"]; + bindings.emplace_back(); + bindings.back()["s"] = makeJSONBinding(std::nullopt, "uri", "d"); + bindings.emplace_back(); + bindings.back()["s"] = makeJSONBinding(std::nullopt, "uri", "g"); + return j; + }(), + expectedXml}; + runSelectQueryTestCase(testCaseLimitOffset); +} + // ____________________________________________________________________________ TEST(ExportQueryExecutionTrees, BinaryExport) { std::string kg = "

31 . 42";