diff --git a/dbms/src/DataStreams/PrettyBlockOutputStream.cpp b/dbms/src/DataStreams/PrettyBlockOutputStream.cpp index f6a7dab3081..87703d83116 100644 --- a/dbms/src/DataStreams/PrettyBlockOutputStream.cpp +++ b/dbms/src/DataStreams/PrettyBlockOutputStream.cpp @@ -79,9 +79,13 @@ void PrettyBlockOutputStream::calculateWidths(const Block & block, WidthsPerColu /// And also calculate widths for names of columns. { - const String & name = elem.name; + /// We need to obtain length in escaped form. + { + WriteBufferFromString out(serialized_value); + writeEscapedString(elem.name, out); + } - name_widths[i] = UTF8::countCodePoints(reinterpret_cast(name.data()), name.size()); + name_widths[i] = UTF8::countCodePoints(reinterpret_cast(serialized_value.data()), serialized_value.size()); max_widths[i] = std::max(max_widths[i], name_widths[i]); } } diff --git a/dbms/src/DataStreams/VerticalRowOutputStream.cpp b/dbms/src/DataStreams/VerticalRowOutputStream.cpp index d12f3382289..ba4a41dcb78 100644 --- a/dbms/src/DataStreams/VerticalRowOutputStream.cpp +++ b/dbms/src/DataStreams/VerticalRowOutputStream.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include @@ -19,11 +20,20 @@ VerticalRowOutputStream::VerticalRowOutputStream( Widths name_widths(columns); size_t max_name_width = 0; + String serialized_value; + for (size_t i = 0; i < columns; ++i) { /// Note that number of code points is just a rough approximation of visible string width. const String & name = sample.getByPosition(i).name; - name_widths[i] = UTF8::countCodePoints(reinterpret_cast(name.data()), name.size()); + + { + /// We need to obtain length in escaped form. + WriteBufferFromString out(serialized_value); + writeEscapedString(name, out); + } + + name_widths[i] = UTF8::countCodePoints(reinterpret_cast(serialized_value.data()), serialized_value.size()); if (name_widths[i] > max_name_width) max_name_width = name_widths[i];