From 610801f1befa22f8106273bc182aeebf82e5d5f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mar=C3=ADn?= Date: Thu, 16 May 2024 12:55:10 +0200 Subject: [PATCH] Revert "Merge pull request #63493 from Volodyachan/fix-tabs-in-pretty-format" This reverts commit 8ed245677d447c0e55a7a9fa84739aa4b670db78, reversing changes made to 7be88cca1f42c3b0a94b337c06e1c93eb31780b2. --- .../Formats/Impl/PrettyBlockOutputFormat.cpp | 27 +++---- .../Formats/Impl/PrettyBlockOutputFormat.h | 4 +- .../Impl/PrettyCompactBlockOutputFormat.cpp | 10 +-- .../Impl/PrettySpaceBlockOutputFormat.cpp | 9 +-- .../00298_enum_width_and_cast.reference | 16 ++--- .../00730_unicode_terminal_format.reference | 18 ++--- .../03148_tabs_in_pretty_format.reference | 72 ------------------- .../03148_tabs_in_pretty_format.sql | 42 ----------- 8 files changed, 35 insertions(+), 163 deletions(-) delete mode 100644 tests/queries/0_stateless/03148_tabs_in_pretty_format.reference delete mode 100644 tests/queries/0_stateless/03148_tabs_in_pretty_format.sql diff --git a/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp b/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp index 8e0b6df2321..41c7bfa316b 100644 --- a/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp +++ b/src/Processors/Formats/Impl/PrettyBlockOutputFormat.cpp @@ -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 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 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(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(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(value.data()), value.size()); } } diff --git a/src/Processors/Formats/Impl/PrettyBlockOutputFormat.h b/src/Processors/Formats/Impl/PrettyBlockOutputFormat.h index d8309fd2637..6673c61c61b 100644 --- a/src/Processors/Formats/Impl/PrettyBlockOutputFormat.h +++ b/src/Processors/Formats/Impl/PrettyBlockOutputFormat.h @@ -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 & 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 { diff --git a/src/Processors/Formats/Impl/PrettyCompactBlockOutputFormat.cpp b/src/Processors/Formats/Impl/PrettyCompactBlockOutputFormat.cpp index 80c4dd7b24c..ce22a3b2864 100644 --- a/src/Processors/Formats/Impl/PrettyCompactBlockOutputFormat.cpp +++ b/src/Processors/Formats/Impl/PrettyCompactBlockOutputFormat.cpp @@ -170,8 +170,6 @@ void PrettyCompactBlockOutputFormat::writeRow( std::vector 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); diff --git a/src/Processors/Formats/Impl/PrettySpaceBlockOutputFormat.cpp b/src/Processors/Formats/Impl/PrettySpaceBlockOutputFormat.cpp index 3fe22580e18..d311f005173 100644 --- a/src/Processors/Formats/Impl/PrettySpaceBlockOutputFormat.cpp +++ b/src/Processors/Formats/Impl/PrettySpaceBlockOutputFormat.cpp @@ -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); diff --git a/tests/queries/0_stateless/00298_enum_width_and_cast.reference b/tests/queries/0_stateless/00298_enum_width_and_cast.reference index 227a7be0a19..706e3f2ae98 100644 --- a/tests/queries/0_stateless/00298_enum_width_and_cast.reference +++ b/tests/queries/0_stateless/00298_enum_width_and_cast.reference @@ -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 │ - └───────┴───┴───────────┴───────┴────────┘ + └──────────┴───┴───────────┴───────┴────────┘ diff --git a/tests/queries/0_stateless/00730_unicode_terminal_format.reference b/tests/queries/0_stateless/00730_unicode_terminal_format.reference index d64fbe57e9e..0bf728b0743 100644 --- a/tests/queries/0_stateless/00730_unicode_terminal_format.reference +++ b/tests/queries/0_stateless/00730_unicode_terminal_format.reference @@ -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: ────── '你好': 你好 diff --git a/tests/queries/0_stateless/03148_tabs_in_pretty_format.reference b/tests/queries/0_stateless/03148_tabs_in_pretty_format.reference deleted file mode 100644 index a0f32016d85..00000000000 --- a/tests/queries/0_stateless/03148_tabs_in_pretty_format.reference +++ /dev/null @@ -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⋯ │ - └────┴───────┴────────┘ diff --git a/tests/queries/0_stateless/03148_tabs_in_pretty_format.sql b/tests/queries/0_stateless/03148_tabs_in_pretty_format.sql deleted file mode 100644 index 161cf6304f6..00000000000 --- a/tests/queries/0_stateless/03148_tabs_in_pretty_format.sql +++ /dev/null @@ -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;