Revert "Merge pull request #63493 from Volodyachan/fix-tabs-in-pretty-format"

This reverts commit 8ed245677d, reversing
changes made to 7be88cca1f.
This commit is contained in:
Raúl Marín 2024-05-16 12:55:10 +02:00
parent a2223f6ec5
commit 610801f1be
8 changed files with 35 additions and 163 deletions

View File

@ -24,7 +24,7 @@ PrettyBlockOutputFormat::PrettyBlockOutputFormat(
/// Note that number of code points is just a rough approximation of visible string width.
void PrettyBlockOutputFormat::calculateWidths(
const Block & header, const Chunk & chunk,
WidthsPerColumn & widths, Widths & max_padded_widths, Widths & name_widths, size_t table_border_width)
WidthsPerColumn & widths, Widths & max_padded_widths, Widths & name_widths)
{
size_t num_rows = std::min(chunk.getNumRows(), format_settings.pretty.max_rows);
@ -42,7 +42,7 @@ void PrettyBlockOutputFormat::calculateWidths(
/// Calculate widths of all values.
String serialized_value;
size_t prefix = format_settings.pretty.output_format_pretty_row_numbers ? row_number_width + table_border_width : table_border_width; // Tab character adjustment
size_t prefix = 2; // Tab character adjustment
for (size_t i = 0; i < num_columns; ++i)
{
const auto & elem = header.getByPosition(i);
@ -187,7 +187,7 @@ void PrettyBlockOutputFormat::writeChunk(const Chunk & chunk, PortKind port_kind
WidthsPerColumn widths;
Widths max_widths;
Widths name_widths;
calculateWidths(header, chunk, widths, max_widths, name_widths, 2);
calculateWidths(header, chunk, widths, max_widths, name_widths);
const GridSymbols & grid_symbols = format_settings.pretty.charset == FormatSettings::Pretty::Charset::UTF8 ?
utf8_grid_symbols :
@ -321,7 +321,6 @@ void PrettyBlockOutputFormat::writeChunk(const Chunk & chunk, PortKind port_kind
std::vector<String> transferred_row(num_columns);
bool has_transferred_row = false;
size_t prefix = format_settings.pretty.output_format_pretty_row_numbers ? row_number_width + 2 : 2;
for (size_t j = 0; j < num_columns; ++j)
{
@ -335,13 +334,11 @@ void PrettyBlockOutputFormat::writeChunk(const Chunk & chunk, PortKind port_kind
serializations[j]->serializeText(*columns[j], i, out_serialize, format_settings);
}
if (cut_to_width && format_settings.pretty.preserve_border_for_multiline_string)
splitValueAtBreakLine(serialized_value, transferred_row[j], cur_width, cut_to_width, prefix);
has_transferred_row |= !transferred_row[j].empty();
splitValueAtBreakLine(serialized_value, transferred_row[j], cur_width);
has_transferred_row |= !transferred_row[j].empty() && cur_width <= cut_to_width;
writeValueWithPadding(serialized_value, cur_width, max_widths[j], cut_to_width,
type.shouldAlignRightInPrettyFormats(), isNumber(type), !transferred_row[j].empty(), false);
prefix += max_widths[j] + 3;
}
writeCString(grid_symbols.bar, out);
@ -502,7 +499,6 @@ void PrettyBlockOutputFormat::writeTransferredRow(const Widths & max_widths, con
std::vector<String> new_transferred_row(num_columns);
bool has_transferred_row = false;
size_t prefix = format_settings.pretty.output_format_pretty_row_numbers ? row_number_width + 2 : 2;
for (size_t j = 0; j < num_columns; ++j)
{
@ -514,13 +510,11 @@ void PrettyBlockOutputFormat::writeTransferredRow(const Widths & max_widths, con
const auto & type = *header.getByPosition(j).type;
size_t cur_width = UTF8::computeWidth(reinterpret_cast<const UInt8 *>(transferred_row[j].data()), transferred_row[j].size());
if (cut_to_width)
splitValueAtBreakLine(transferred_row[j], new_transferred_row[j], cur_width, cut_to_width, prefix);
has_transferred_row |= !new_transferred_row[j].empty();
splitValueAtBreakLine(transferred_row[j], new_transferred_row[j], cur_width);
has_transferred_row |= !new_transferred_row[j].empty() && cur_width <= cut_to_width;
writeValueWithPadding(transferred_row[j], cur_width, max_widths[j], cut_to_width,
type.shouldAlignRightInPrettyFormats(), isNumber(type), !new_transferred_row[j].empty(), !transferred_row[j].empty());
prefix += max_widths[j] + 3;
}
if (!space_block)
@ -531,14 +525,13 @@ void PrettyBlockOutputFormat::writeTransferredRow(const Widths & max_widths, con
writeTransferredRow(max_widths, header, new_transferred_row, cut_to_width, space_block);
}
void PrettyBlockOutputFormat::splitValueAtBreakLine(String & value, String & transferred_value, size_t & value_width, size_t cut_to_width, size_t prefix)
void PrettyBlockOutputFormat::splitValueAtBreakLine(String & value, String & transferred_value, size_t & value_width)
{
if (size_t break_line_pos = value.find_first_of('\n'); break_line_pos != String::npos)
{
value_width = UTF8::computeWidth(reinterpret_cast<const UInt8 *>(value.data()), break_line_pos, prefix);
if (value_width <= cut_to_width)
transferred_value = value.substr(break_line_pos + 1);
transferred_value = value.substr(break_line_pos + 1);
value = value.substr(0, break_line_pos);
value_width = UTF8::computeWidth(reinterpret_cast<const UInt8 *>(value.data()), value.size());
}
}

View File

@ -44,7 +44,7 @@ protected:
void calculateWidths(
const Block & header, const Chunk & chunk,
WidthsPerColumn & widths, Widths & max_padded_widths, Widths & name_widths, size_t table_border_width);
WidthsPerColumn & widths, Widths & max_padded_widths, Widths & name_widths);
void writeValueWithPadding(
String & value, size_t value_width, size_t pad_to_width, size_t cut_to_width,
@ -52,7 +52,7 @@ protected:
void writeTransferredRow(const Widths & max_widths, const Block & header, std::vector<String> & transferred_row, size_t cut_to_width, bool space_block);
void splitValueAtBreakLine(String & value, String & transferred_value, size_t & value_width, size_t cut_to_width, size_t prefix);
void splitValueAtBreakLine(String & value, String & transferred_value, size_t & value_width);
void resetFormatterImpl() override
{

View File

@ -170,8 +170,6 @@ void PrettyCompactBlockOutputFormat::writeRow(
std::vector<String> transferred_row(num_columns);
bool has_transferred_row = false;
size_t prefix = format_settings.pretty.output_format_pretty_row_numbers ? row_number_width + 2 : 2;
for (size_t j = 0; j < num_columns; ++j)
{
if (j != 0)
@ -185,13 +183,11 @@ void PrettyCompactBlockOutputFormat::writeRow(
serializations[j]->serializeText(*columns[j], row_num, out_serialize, format_settings);
}
if (cut_to_width && format_settings.pretty.preserve_border_for_multiline_string)
splitValueAtBreakLine(serialized_value, transferred_row[j], cur_width, cut_to_width, prefix);
has_transferred_row |= !transferred_row[j].empty();
splitValueAtBreakLine(serialized_value, transferred_row[j], cur_width);
has_transferred_row |= !transferred_row[j].empty() && cur_width <= cut_to_width;
writeValueWithPadding(serialized_value, cur_width, max_widths[j], cut_to_width,
type.shouldAlignRightInPrettyFormats(), isNumber(type), !transferred_row[j].empty(), false);
prefix += max_widths[j] + 3;
}
writeCString(grid_symbols.bar, out);
@ -212,7 +208,7 @@ void PrettyCompactBlockOutputFormat::writeChunk(const Chunk & chunk, PortKind po
WidthsPerColumn widths;
Widths max_widths;
Widths name_widths;
calculateWidths(header, chunk, widths, max_widths, name_widths, 2);
calculateWidths(header, chunk, widths, max_widths, name_widths);
writeHeader(header, max_widths, name_widths);

View File

@ -31,7 +31,7 @@ void PrettySpaceBlockOutputFormat::writeChunk(const Chunk & chunk, PortKind port
WidthsPerColumn widths;
Widths max_widths;
Widths name_widths;
calculateWidths(header, chunk, widths, max_widths, name_widths, 1);
calculateWidths(header, chunk, widths, max_widths, name_widths);
if (format_settings.pretty.output_format_pretty_row_numbers)
writeString(String(row_number_width, ' '), out);
@ -88,7 +88,6 @@ void PrettySpaceBlockOutputFormat::writeChunk(const Chunk & chunk, PortKind port
writeCString("\033[0m", out);
}
size_t prefix = format_settings.pretty.output_format_pretty_row_numbers ? row_number_width + 1 : 1;
for (size_t column = 0; column < num_columns; ++column)
{
if (column != 0)
@ -102,13 +101,11 @@ void PrettySpaceBlockOutputFormat::writeChunk(const Chunk & chunk, PortKind port
serializations[column]->serializeText(*columns[column], row, out_serialize, format_settings);
}
if (cut_to_width && format_settings.pretty.preserve_border_for_multiline_string)
splitValueAtBreakLine(serialized_value, transferred_row[column], cur_width, cur_width, prefix);
has_transferred_row |= !transferred_row[column].empty();
splitValueAtBreakLine(serialized_value, transferred_row[column], cur_width);
has_transferred_row |= !transferred_row[column].empty() && cur_width <= cut_to_width;
writeValueWithPadding(serialized_value, cur_width, max_widths[column], cut_to_width,
type.shouldAlignRightInPrettyFormats(), isNumber(type), !transferred_row[column].empty(), false);
prefix += max_widths[column] + 3;
}
writeReadableNumberTip(chunk);

View File

@ -5,13 +5,13 @@
1. │ Hello │ 0 │
2. │ \ │ 0 │
└───────┴───┘
┌─x─────┬─y─┐
1. │ Hello │ 0 │
2. │ \ │ 0 │
┌─x────────┬─y─┐
1. │ Hello │ 0 │
2. │ \ │ 0 │
3. │ \t │ 0 │
└───────┴───┘
┌─x─────┬─y─┬─toInt8(x)─┬─s─────┬─casted─┐
1. │ Hello │ 0 │ -100 │ Hello │ Hello │
2. │ \ │ 0 │ 0 │ \ │ \ │
└──────────┴───┘
┌─x────────┬─y─┬─toInt8(x)─┬─s─────┬─casted─┐
1. │ Hello │ 0 │ -100 │ Hello │ Hello │
2. │ \ │ 0 │ 0 │ \ │ \ │
3. │ \t │ 0 │ 111 │ \t │ \t │
└───────┴───┴───────────┴───────┴────────┘
└──────────┴───┴───────────┴───────┴────────┘

View File

@ -63,11 +63,11 @@
┡━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
13. │ Ahoj │ Tento kód můžete upravit a spustit │
└──────┴────────────────────────────────────┘
┏━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┓
┃ c1 ┃ c2 ┃
┡━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━┩
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━┓
┃ c1 ┃ c2 ┃
┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━┩
14. │ Tabs Tabs │ Non-first Tabs │
└─────────────────┴───────────────────────┘
└─────────────┴───────────────────────┘
┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃ c1 ┃ c2 ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩
@ -78,11 +78,11 @@
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━┩
16. │ Russian ё and ё │ Zero bytes in middle │
└──────────────────┴────────────────────────┘
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ 'Tabs \t Tabs' ┃ 'Long\tTitle' ┃
┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
1. │ Tabs Tabs │ Long Title │
└──────────────────┴───────────────┘
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓
┃ 'Tabs \t Tabs' ┃ 'Long\tTitle' ┃
┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩
1. │ Tabs Tabs │ Long Title
└────────────────┴───────────────┘
Row 1:
──────
'你好': 你好

View File

@ -1,72 +0,0 @@
┏━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━━━━┓
┃ id ┃ value ┃ value1 ┃
┡━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━━━━┩
│ 0 │ test test │ something │
└────┴───────────┴────────────────┘
┏━━━━┳━━━━━━━━━━━┳━━━━━━━━━━━━━┓
┃ id ┃ value ┃ value1 ┃
┡━━━━╇━━━━━━━━━━━╇━━━━━━━━━━━━━┩
1. │ 0 │ test test │ something │
└────┴───────────┴─────────────┘
┌─id─┬─value─┬─value1────┐
│ 0 │ test …│ something │
│ │… test │ │
└────┴───────┴───────────┘
┌─id─┬─value──────┬─value1────┐
1. │ 0 │ test …│ something │
│ │… test │ │
└────┴────────────┴───────────┘
id value value1
0 test … something
… test
id value value1
1. 0 test … something
… test
┌─id─┬─value─────┬─value1────┐
│ 0 │ something │ test …│
│ │ │… test │
└────┴───────────┴───────────┘
┌─id─┬─value─────┬─value1─┐
1. │ 0 │ something │ test …│
│ │ │… test │
└────┴───────────┴────────┘
id value value1
0 something test …
… test
id value value1
1. 0 something test …
… test
┏━━━━┳━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ id ┃ value ┃ value1 ┃
┡━━━━╇━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
│ 0 │ something │ test …│
│ │ │… test │
├────┼───────────────────┼───────────┤
│ 1 │ some thing │ test …│
│ │ │… test │
└────┴───────────────────┴───────────┘
┏━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━┓
┃ id ┃ value ┃ value1 ┃
┡━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━┩
1. │ 0 │ something │ test …│
│ │ │… test │
├────┼────────────────────────┼───────────┤
2. │ 1 │ some thing │ test …│
│ │ │… test │
└────┴────────────────────────┴───────────┘
┏━━━━┳━━━━━━━┳━━━━━━━━┓
┃ id ┃ value ┃ value1 ┃
┡━━━━╇━━━━━━━╇━━━━━━━━┩
│ 0 │ somet⋯│ test …│
│ │ │…testt⋯ │
└────┴───────┴────────┘
┏━━━━┳━━━━━━━┳━━━━━━━━┓
┃ id ┃ value ┃ value1 ┃
┡━━━━╇━━━━━━━╇━━━━━━━━┩
1. │ 0 │ somet⋯│ test …│
│ │ │…testt⋯ │
└────┴───────┴────────┘

View File

@ -1,42 +0,0 @@
DROP TABLE IF EXISTS t_tabs;
CREATE TABLE t_tabs (id UInt64, value String, value1 String) ENGINE=MergeTree ORDER BY id;
INSERT INTO t_tabs VALUES(0, 'test test', '\tsomething');
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyMonoBlock SETTINGS output_format_pretty_row_numbers = 0;
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyMonoBlock;
TRUNCATE TABLE t_tabs;
INSERT INTO t_tabs VALUES(0, 'test\n\ttest', 'something');
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyCompactNoEscapes SETTINGS output_format_pretty_row_numbers = 0;
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyCompactNoEscapes;
SELECT * FROM t_tabs FORMAT PrettySpace SETTINGS output_format_pretty_row_numbers = 0;
SELECT * FROM t_tabs FORMAT PrettySpace;
TRUNCATE TABLE t_tabs;
INSERT INTO t_tabs VALUES(0, 'something', 'test\n\ttest');
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyCompactNoEscapes SETTINGS output_format_pretty_row_numbers = 0;
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyCompactNoEscapes;
SELECT * FROM t_tabs FORMAT PrettySpace SETTINGS output_format_pretty_row_numbers = 0;
SELECT * FROM t_tabs FORMAT PrettySpace;
INSERT INTO t_tabs VALUES(1, '\tsome\tthing\t', 'test\n\ttest');
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyMonoBlock SETTINGS output_format_pretty_row_numbers = 0;
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyMonoBlock;
TRUNCATE TABLE t_tabs;
SET output_format_pretty_max_value_width = 5;
INSERT INTO t_tabs VALUES(0, 'someth\ning\t', 'test\ntesttest');
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyMonoBlock SETTINGS output_format_pretty_row_numbers = 0;
SELECT * FROM t_tabs ORDER BY id FORMAT PrettyMonoBlock;
DROP TABLE t_tabs;