TODO(Ziyi): I'm inclined to move this as a QueryResult interface.
| 27 | |
| 28 | // TODO(Ziyi): I'm inclined to move this as a QueryResult interface. |
| 29 | std::string JsonPrinter::printBody(QueryResult& queryResult, MemoryManager& mm) const { |
| 30 | std::string result; |
| 31 | std::vector<std::shared_ptr<ValueVector>> resultVectors; |
| 32 | std::vector<ValueVector*> scanVectors; |
| 33 | for (auto& type : queryResult.getColumnDataTypes()) { |
| 34 | auto resultVector = std::make_shared<ValueVector>(type.copy(), &mm, resultVectorState); |
| 35 | resultVectors.push_back(resultVector); |
| 36 | scanVectors.push_back(resultVector.get()); |
| 37 | } |
| 38 | std::span<ValueVector*> vectorsToScan{scanVectors}; |
| 39 | DASSERT(queryResult.getType() == QueryResultType::FTABLE); |
| 40 | auto& table = queryResult.constCast<MaterializedQueryResult>().getFactorizedTable(); |
| 41 | uint64_t numTuplesScanned = 0; |
| 42 | auto maxNumTuplesToScanInBatch = table.hasUnflatCol() ? 1 : DEFAULT_VECTOR_CAPACITY; |
| 43 | auto totalNumTuplesToScan = table.getNumTuples(); |
| 44 | while (numTuplesScanned < totalNumTuplesToScan) { |
| 45 | auto numTuplesToScanInBatch = |
| 46 | std::min<uint64_t>(maxNumTuplesToScanInBatch, totalNumTuplesToScan - numTuplesScanned); |
| 47 | table.scan(vectorsToScan, numTuplesScanned, numTuplesToScanInBatch); |
| 48 | numTuplesScanned += numTuplesToScanInBatch; |
| 49 | auto queryResultsInJson = |
| 50 | json_extension::jsonifyQueryResult(resultVectors, queryResult.getColumnNames()); |
| 51 | for (auto i = 0u; i < queryResultsInJson.size() - 1; i++) { |
| 52 | result += jsonToString(queryResultsInJson[i]); |
| 53 | result += printDelim(); |
| 54 | result += JsonPrinter::NEW_LINE; |
| 55 | } |
| 56 | // Only print the delimiter when it is not the last record. |
| 57 | result += jsonToString(queryResultsInJson[queryResultsInJson.size() - 1]); |
| 58 | if (numTuplesScanned != totalNumTuplesToScan) { |
| 59 | result += printDelim(); |
| 60 | } |
| 61 | result += JsonPrinter::NEW_LINE; |
| 62 | } |
| 63 | return result; |
| 64 | } |
| 65 | |
| 66 | } // namespace main |
| 67 | } // namespace lbug |
nothing calls this directly
no test coverage detected