Skip to content

Commit

Permalink
Merge pull request #1120 from kuzudb/fix-941
Browse files Browse the repository at this point in the history
omit long query result
  • Loading branch information
aziz-mu committed Dec 16, 2022
2 parents 3df9d1d + ce127dc commit 05d9892
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/include/processor/result/flat_tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ class FlatTuple {

ResultValue* getResultValue(uint32_t valIdx);

string toString(const vector<uint32_t>& colsWidth, const string& delimiter = "|");
string toString(const vector<uint32_t>& colsWidth, const string& delimiter = "|",
const uint32_t maxWidth = -1);

private:
vector<unique_ptr<ResultValue>> resultValues;
Expand Down
7 changes: 6 additions & 1 deletion src/processor/result/flat_tuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,14 @@ ResultValue* FlatTuple::getResultValue(uint32_t valIdx) {
return resultValues[valIdx].get();
}

string FlatTuple::toString(const vector<uint32_t>& colsWidth, const string& delimiter) {
string FlatTuple::toString(
const vector<uint32_t>& colsWidth, const string& delimiter, const uint32_t maxWidth) {
ostringstream result;
for (auto i = 0ul; i < resultValues.size(); i++) {
string value = resultValues[i]->toString();
if (value.length() > maxWidth) {
value = value.substr(0, maxWidth - 3) + "...";
}
if (colsWidth[i] != 0) {
value = " " + value + " ";
}
Expand All @@ -113,6 +117,7 @@ string FlatTuple::toString(const vector<uint32_t>& colsWidth, const string& deli
fieldLen += Utf8Proc::renderWidth(value.c_str(), chrIter);
chrIter = utf8proc_next_grapheme(value.c_str(), value.length(), chrIter);
}
fieldLen = min(fieldLen, maxWidth + 2);
if (colsWidth[i] != 0) {
result << value << string(colsWidth[i] - fieldLen, ' ');
} else {
Expand Down
6 changes: 3 additions & 3 deletions tools/shell/embedded_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ void EmbeddedShell::printExecutionResult(QueryResult& queryResult) const {
auto& oss = querySummary->getPlanAsOstream();
printf("%s", oss.str().c_str());
} else {
const uint32_t maxWidth = 80;
uint64_t numTuples = queryResult.getNumTuples();
vector<uint32_t> colsWidth(queryResult.getNumColumns(), 2);
for (auto i = 0u; i < colsWidth.size(); i++) {
Expand All @@ -350,8 +351,7 @@ void EmbeddedShell::printExecutionResult(QueryResult& queryResult) const {
}
// An extra 2 spaces are added for an extra space on either
// side of the string.
fieldLen += 2;
colsWidth[i] = max(colsWidth[i], fieldLen);
colsWidth[i] = max(colsWidth[i], min(fieldLen, maxWidth) + 2);
}
}
for (auto width : colsWidth) {
Expand All @@ -374,7 +374,7 @@ void EmbeddedShell::printExecutionResult(QueryResult& queryResult) const {
queryResult.resetIterator();
while (queryResult.hasNext()) {
auto tuple = queryResult.getNext();
printf("|%s|\n", tuple->toString(colsWidth, "|").c_str());
printf("|%s|\n", tuple->toString(colsWidth, "|", maxWidth).c_str());
printf("%s\n", lineSeparator.c_str());
}

Expand Down

0 comments on commit 05d9892

Please sign in to comment.