2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <DataStreams/PrettyCompactBlockOutputStream.h>
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-07-25 18:26:45 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
|
|
|
|
extern const int ILLEGAL_COLUMN;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
void PrettyCompactBlockOutputStream::writeHeader(
|
2017-04-01 07:20:54 +00:00
|
|
|
const Block & block,
|
2017-07-11 21:41:37 +00:00
|
|
|
const Widths & max_widths,
|
|
|
|
const Widths & name_widths)
|
2011-11-28 04:05:53 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Names
|
|
|
|
writeCString("┌─", ostr);
|
|
|
|
for (size_t i = 0; i < max_widths.size(); ++i)
|
|
|
|
{
|
|
|
|
if (i != 0)
|
|
|
|
writeCString("─┬─", ostr);
|
|
|
|
|
2017-07-11 21:41:37 +00:00
|
|
|
const ColumnWithTypeAndName & col = block.getByPosition(i);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
if (col.type->isNumeric())
|
|
|
|
{
|
|
|
|
for (size_t k = 0; k < max_widths[i] - name_widths[i]; ++k)
|
|
|
|
writeCString("─", ostr);
|
|
|
|
|
|
|
|
if (!no_escapes)
|
|
|
|
writeCString("\033[1m", ostr);
|
|
|
|
writeEscapedString(col.name, ostr);
|
|
|
|
if (!no_escapes)
|
|
|
|
writeCString("\033[0m", ostr);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!no_escapes)
|
|
|
|
writeCString("\033[1m", ostr);
|
|
|
|
writeEscapedString(col.name, ostr);
|
|
|
|
if (!no_escapes)
|
|
|
|
writeCString("\033[0m", ostr);
|
|
|
|
|
|
|
|
for (size_t k = 0; k < max_widths[i] - name_widths[i]; ++k)
|
|
|
|
writeCString("─", ostr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writeCString("─┐\n", ostr);
|
2013-06-18 09:56:11 +00:00
|
|
|
}
|
2011-11-28 04:05:53 +00:00
|
|
|
|
2017-07-11 21:41:37 +00:00
|
|
|
void PrettyCompactBlockOutputStream::writeBottom(const Widths & max_widths)
|
2013-06-18 09:56:11 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Create delimiters
|
|
|
|
std::stringstream bottom_separator;
|
2013-06-18 09:56:11 +00:00
|
|
|
|
2017-07-11 21:41:37 +00:00
|
|
|
bottom_separator << "└";
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < max_widths.size(); ++i)
|
|
|
|
{
|
|
|
|
if (i != 0)
|
2017-07-11 21:41:37 +00:00
|
|
|
bottom_separator << "┴";
|
2011-11-28 04:05:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t j = 0; j < max_widths[i] + 2; ++j)
|
2017-07-11 21:41:37 +00:00
|
|
|
bottom_separator << "─";
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2017-07-11 21:41:37 +00:00
|
|
|
bottom_separator << "┘\n";
|
2013-06-18 09:56:11 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
writeString(bottom_separator.str(), ostr);
|
2013-06-18 09:56:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PrettyCompactBlockOutputStream::writeRow(
|
2017-07-11 21:41:37 +00:00
|
|
|
size_t row_num,
|
2017-04-01 07:20:54 +00:00
|
|
|
const Block & block,
|
2017-07-11 21:41:37 +00:00
|
|
|
const WidthsPerColumn & widths,
|
2017-12-01 19:34:51 +00:00
|
|
|
const Widths & max_widths)
|
2013-06-18 09:56:11 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t columns = max_widths.size();
|
2014-08-15 00:08:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
writeCString("│ ", ostr);
|
2013-06-18 09:56:11 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t j = 0; j < columns; ++j)
|
|
|
|
{
|
|
|
|
if (j != 0)
|
|
|
|
writeCString(" │ ", ostr);
|
2013-06-18 09:56:11 +00:00
|
|
|
|
2017-07-11 21:41:37 +00:00
|
|
|
writeValueWithPadding(block.getByPosition(j), row_num, widths[j].empty() ? max_widths[j] : widths[j][row_num], max_widths[j]);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
2011-11-28 04:05:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
writeCString(" │\n", ostr);
|
2013-06-18 09:56:11 +00:00
|
|
|
}
|
|
|
|
|
2017-07-11 21:41:37 +00:00
|
|
|
void PrettyCompactBlockOutputStream::write(const Block & block)
|
2013-06-18 09:56:11 +00:00
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (total_rows >= max_rows)
|
|
|
|
{
|
2017-07-11 21:41:37 +00:00
|
|
|
total_rows += block.rows();
|
2017-04-01 07:20:54 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-08-15 00:08:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
size_t rows = block.rows();
|
2013-06-18 09:56:11 +00:00
|
|
|
|
2017-07-11 21:41:37 +00:00
|
|
|
WidthsPerColumn widths;
|
|
|
|
Widths max_widths;
|
|
|
|
Widths name_widths;
|
|
|
|
calculateWidths(block, widths, max_widths, name_widths);
|
2014-08-15 00:08:15 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
writeHeader(block, max_widths, name_widths);
|
2013-06-18 09:56:11 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < rows && total_rows + i < max_rows; ++i)
|
2017-12-01 19:34:51 +00:00
|
|
|
writeRow(i, block, widths, max_widths);
|
2013-06-18 09:56:11 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
writeBottom(max_widths);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
total_rows += rows;
|
2011-11-28 04:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|