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

Method printTruncatedExecutionResult

tools/shell/embedded_shell.cpp:1140–1599  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1138}
1139
1140void EmbeddedShell::printTruncatedExecutionResult(QueryResult& queryResult) const {
1141 auto& baseTablePrinter = printer->constCast<BaseTablePrinter>();
1142 auto querySummary = queryResult.getQuerySummary();
1143 uint64_t numTuples = queryResult.getNumTuples();
1144 std::vector<uint32_t> colsWidth(queryResult.getNumColumns(), 2);
1145 // calculate the width of each column name/type
1146 for (auto i = 0u; i < colsWidth.size(); i++) {
1147 colsWidth[i] = std::max(queryResult.getColumnNames()[i].length(),
1148 queryResult.getColumnDataTypes()[i].toString().length()) +
1149 2;
1150 }
1151 uint64_t rowCount = 0;
1152 // calculate the width of each tuple value
1153 while (queryResult.hasNext()) {
1154 if (numTuples > maxRowSize && rowCount >= (maxRowSize / 2) + (maxRowSize % 2 != 0) &&
1155 rowCount < numTuples - maxRowSize / 2) {
1156 auto tuple = queryResult.getNext();
1157 rowCount++;
1158 continue;
1159 }
1160 auto tuple = queryResult.getNext();
1161 for (auto i = 0u; i < colsWidth.size(); i++) {
1162 if (tuple->getValue(i)->isNull()) {
1163 continue;
1164 }
1165 std::string tupleString = tuple->getValue(i)->toString();
1166 uint32_t fieldLen = 0;
1167 uint32_t chrIter = 0;
1168 while (chrIter < tupleString.length()) {
1169 fieldLen += Utf8Proc::renderWidth(tupleString.c_str(), chrIter);
1170 chrIter =
1171 utf8proc_next_grapheme(tupleString.c_str(), tupleString.length(), chrIter);
1172 }
1173 // An extra 2 spaces are added for an extra space on either
1174 // side of the std::string.
1175 colsWidth[i] = std::max(colsWidth[i], fieldLen + 2);
1176 }
1177 rowCount++;
1178 }
1179
1180 // calculate the maximum width of the table
1181 uint32_t sumGoal = BaseTablePrinter::MIN_TRUNCATED_WIDTH;
1182 uint32_t maxWidth = BaseTablePrinter::MIN_TRUNCATED_WIDTH;
1183 ;
1184 if (colsWidth.size() == 1) {
1185 uint32_t minDisplayWidth =
1186 BaseTablePrinter::MIN_TRUNCATED_WIDTH + BaseTablePrinter::SMALL_TABLE_SEPERATOR_LENGTH;
1187 if (maxPrintWidth > minDisplayWidth) {
1188 sumGoal = maxPrintWidth - 2;
1189 } else {
1190 sumGoal =
1191 std::max((uint32_t)(getColumns(STDIN_FILENO, STDOUT_FILENO) - colsWidth.size() - 1),
1192 minDisplayWidth);
1193 }
1194 } else if (colsWidth.size() > 1) {
1195 uint32_t minDisplayWidth = BaseTablePrinter::SMALL_TABLE_SEPERATOR_LENGTH +
1196 BaseTablePrinter::MIN_TRUNCATED_WIDTH * 2;
1197 if (maxPrintWidth > minDisplayWidth) {

Callers

nothing calls this directly

Calls 15

getColumnsFunction · 0.85
getQuerySummaryMethod · 0.80
lengthMethod · 0.80
getColumnDataTypesMethod · 0.80
getCompilingTimeMethod · 0.80
getNumTuplesMethod · 0.45
getNumColumnsMethod · 0.45
sizeMethod · 0.45
getColumnNamesMethod · 0.45
toStringMethod · 0.45
hasNextMethod · 0.45
getNextMethod · 0.45

Tested by

no test coverage detected