This commit is contained in:
flynn 2023-01-02 12:37:43 +00:00
parent 3a1dd045dd
commit 7b487dd923
3 changed files with 246 additions and 9 deletions

View File

@ -16,6 +16,7 @@ namespace DB
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
@ -37,8 +38,8 @@ void PrettyBlockOutputFormat::calculateWidths(
{
size_t num_rows = std::min(chunk.getNumRows(), format_settings.pretty.max_rows);
/// len(num_rows) + len(". ")
row_number_width = static_cast<size_t>(std::floor(std::log10(num_rows))) + 3;
/// len(num_rows + total_rows) + len(". ")
row_number_width = static_cast<size_t>(std::floor(std::log10(num_rows + total_rows))) + 3;
size_t num_columns = chunk.getNumColumns();
const auto & columns = chunk.getColumns();
@ -296,6 +297,10 @@ void PrettyBlockOutputFormat::writeChunk(const Chunk & chunk, PortKind port_kind
{
// Write row number;
auto row_num_string = std::to_string(i + 1 + total_rows) + ". ";
size_t black_width = row_number_width - row_num_string.size();
if (black_width > row_number_width)
throw Exception(
ErrorCodes::LOGICAL_ERROR, "blak width overflow {}, {}, {}", black_width, row_num_string.size(), row_number_width);
for (size_t j = 0; j < row_number_width - row_num_string.size(); ++j)
{
writeCString(" ", out);

View File

@ -258,3 +258,235 @@
a
2. 2
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
1. │ 0 │
└────────┘
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
2. │ 1 │
└────────┘
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
3. │ 2 │
└────────┘
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
4. │ 3 │
└────────┘
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
5. │ 4 │
└────────┘
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
6. │ 5 │
└────────┘
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
7. │ 6 │
└────────┘
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
8. │ 7 │
└────────┘
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
9. │ 8 │
└────────┘
┏━━━━━━━━┓
number ┃
┡━━━━━━━━┩
10. │ 9 │
└────────┘
┌─number─┐
1. │ 0 │
└────────┘
┌─number─┐
2. │ 1 │
└────────┘
┌─number─┐
3. │ 2 │
└────────┘
┌─number─┐
4. │ 3 │
└────────┘
┌─number─┐
5. │ 4 │
└────────┘
┌─number─┐
6. │ 5 │
└────────┘
┌─number─┐
7. │ 6 │
└────────┘
┌─number─┐
8. │ 7 │
└────────┘
┌─number─┐
9. │ 8 │
└────────┘
┌─number─┐
10. │ 9 │
└────────┘
┌─number─┐
1. │ 0 │
2. │ 1 │
3. │ 2 │
4. │ 3 │
5. │ 4 │
6. │ 5 │
7. │ 6 │
8. │ 7 │
9. │ 8 │
10. │ 9 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
1. │ 0 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
2. │ 1 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
3. │ 2 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
4. │ 3 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
5. │ 4 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
6. │ 5 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
7. │ 6 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
8. │ 7 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
9. │ 8 │
└────────┘
┏━━━━━━━━┓
┃ number ┃
┡━━━━━━━━┩
10. │ 9 │
└────────┘
┌─number─┐
1. │ 0 │
└────────┘
┌─number─┐
2. │ 1 │
└────────┘
┌─number─┐
3. │ 2 │
└────────┘
┌─number─┐
4. │ 3 │
└────────┘
┌─number─┐
5. │ 4 │
└────────┘
┌─number─┐
6. │ 5 │
└────────┘
┌─number─┐
7. │ 6 │
└────────┘
┌─number─┐
8. │ 7 │
└────────┘
┌─number─┐
9. │ 8 │
└────────┘
┌─number─┐
10. │ 9 │
└────────┘
number
1. 0
number
2. 1
number
3. 2
number
4. 3
number
5. 4
number
6. 5
number
7. 6
number
8. 7
number
9. 8
number
10. 9
number
1. 0
number
2. 1
number
3. 2
number
4. 3
number
5. 4
number
6. 5
number
7. 6
number
8. 7
number
9. 8
number
10. 9

View File

@ -24,10 +24,10 @@ SELECT * FROM (SELECT 1 AS a UNION ALL SELECT 2 as a) ORDER BY a FORMAT PrettyCo
SELECT * FROM (SELECT 1 AS a UNION ALL SELECT 2 as a) ORDER BY a FORMAT PrettySpace;
SELECT * FROM (SELECT 1 AS a UNION ALL SELECT 2 as a) ORDER BY a FORMAT PrettySpaceNoEscapes;
-- SELECT * FROM numbers(10) ORDER BY number FORMAT Pretty;
-- SELECT * FROM numbers(10) ORDER BY number FORMAT PrettyCompact;
-- SELECT * FROM numbers(10) ORDER BY number FORMAT PrettyCompactMonoBlock;
-- SELECT * FROM numbers(10) ORDER BY number FORMAT PrettyNoEscapes;
-- SELECT * FROM numbers(10) ORDER BY number FORMAT PrettyCompactNoEscapes;
-- SELECT * FROM numbers(10) ORDER BY number FORMAT PrettySpace
-- SELECT * FROM numbers(10) ORDER BY number FORMAT PrettySpaceNoEscapes;
SELECT * FROM numbers(10) ORDER BY number FORMAT Pretty;
SELECT * FROM numbers(10) ORDER BY number FORMAT PrettyCompact;
SELECT * FROM numbers(10) ORDER BY number FORMAT PrettyCompactMonoBlock;
SELECT * FROM numbers(10) ORDER BY number FORMAT PrettyNoEscapes;
SELECT * FROM numbers(10) ORDER BY number FORMAT PrettyCompactNoEscapes;
SELECT * FROM numbers(10) ORDER BY number FORMAT PrettySpace;
SELECT * FROM numbers(10) ORDER BY number FORMAT PrettySpaceNoEscapes;