Run the given SPARQL `query` on the given Turtle `kg` and export the result as JSON. `mediaType` must be `sparqlJSON` or `qleverJSON`.
| 67 | // Run the given SPARQL `query` on the given Turtle `kg` and export the result |
| 68 | // as JSON. `mediaType` must be `sparqlJSON` or `qleverJSON`. |
| 69 | nlohmann::json runJSONQuery(const std::string& kg, const std::string& query, |
| 70 | ad_utility::MediaType mediaType, |
| 71 | bool useTextIndex = false, |
| 72 | std::optional<size_t> exportLimit = std::nullopt) { |
| 73 | ad_utility::testing::TestIndexConfig config{kg}; |
| 74 | config.createTextIndex = useTextIndex; |
| 75 | auto qec = ad_utility::testing::getQec(std::move(config)); |
| 76 | // TODO<joka921> There is a bug in the caching that we have yet to trace. |
| 77 | // This cache clearing should not be necessary. |
| 78 | qec->clearCacheUnpinnedOnly(); |
| 79 | auto cancellationHandle = |
| 80 | std::make_shared<ad_utility::CancellationHandle<>>(); |
| 81 | QueryPlanner qp{qec, cancellationHandle}; |
| 82 | auto pq = parseQuery(query); |
| 83 | pq._limitOffset.exportLimit_ = exportLimit; |
| 84 | auto qet = qp.createExecutionTree(pq); |
| 85 | ad_utility::Timer timer{ad_utility::Timer::Started}; |
| 86 | std::string resStr; |
| 87 | for (auto c : ExportQueryExecutionTrees::computeResult( |
| 88 | pq, qet, mediaType, timer, std::move(cancellationHandle))) { |
| 89 | resStr += c; |
| 90 | } |
| 91 | return nlohmann::json::parse(resStr); |
| 92 | } |
| 93 | |
| 94 | // A test case that tests the correct execution and exporting of a SELECT query |
| 95 | // in various formats. |
no test coverage detected