MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / printBody

Method printBody

tools/shell/printer/json_printer.cpp:29–64  ·  view source on GitHub ↗

TODO(Ziyi): I'm inclined to move this as a QueryResult interface.

Source from the content-addressed store, hash-verified

27
28// TODO(Ziyi): I'm inclined to move this as a QueryResult interface.
29std::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

Callers

nothing calls this directly

Calls 13

jsonifyQueryResultFunction · 0.85
jsonToStringFunction · 0.85
getColumnDataTypesMethod · 0.80
getFactorizedTableMethod · 0.80
hasUnflatColMethod · 0.80
copyMethod · 0.45
push_backMethod · 0.45
getMethod · 0.45
getTypeMethod · 0.45
getNumTuplesMethod · 0.45
scanMethod · 0.45
getColumnNamesMethod · 0.45

Tested by

no test coverage detected