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 1047 #1094

Merged
merged 1 commit into from
Dec 7, 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
16 changes: 15 additions & 1 deletion src/processor/result/flat_tuple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include "common/type_utils.h"
#include "common/utils.h"
#include "utf8proc.h"
#include "utf8proc_wrapper.h"

using namespace kuzu::utf8proc;

namespace kuzu {
namespace processor {
Expand Down Expand Up @@ -103,7 +107,17 @@ string FlatTuple::toString(const vector<uint32_t>& colsWidth, const string& deli
if (colsWidth[i] != 0) {
value = " " + value + " ";
}
result << left << setw((int)colsWidth[i]) << setfill(' ') << value;
uint32_t fieldLen = 0;
uint32_t chrIter = 0;
while (chrIter < value.length()) {
fieldLen += Utf8Proc::renderWidth(value.c_str(), chrIter);
chrIter = utf8proc_next_grapheme(value.c_str(), value.length(), chrIter);
}
if (colsWidth[i] != 0) {
result << value << string(colsWidth[i] - fieldLen, ' ');
} else {
result << value;
}
if (i != resultValues.size() - 1) {
result << delimiter;
}
Expand Down
15 changes: 12 additions & 3 deletions tools/shell/embedded_shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,18 @@ void EmbeddedShell::printExecutionResult(QueryResult& queryResult) const {
if (tuple->getResultValue(i)->isNullVal()) {
continue;
}
uint32_t fieldLen = tuple->getResultValue(i)->toString().length() + 2;
colsWidth[i] =
max(colsWidth[i], (fieldLen > colsWidth[i]) ? fieldLen : colsWidth[i]);
string tupleString = tuple->getResultValue(i)->toString();
uint32_t fieldLen = 0;
uint32_t chrIter = 0;
while (chrIter < tupleString.length()) {
fieldLen += Utf8Proc::renderWidth(tupleString.c_str(), chrIter);
chrIter =
utf8proc_next_grapheme(tupleString.c_str(), tupleString.length(), chrIter);
}
// An extra 2 spaces are added for an extra space on either
// side of the string.
fieldLen += 2;
aziz-mu marked this conversation as resolved.
Show resolved Hide resolved
colsWidth[i] = max(colsWidth[i], fieldLen);
}
}
for (auto width : colsWidth) {
Expand Down