Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 941 #1120

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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