2017-04-01 09:19:00 +00:00
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/WriteHelpers.h>
|
|
|
|
#include <DataStreams/PrettySpaceBlockOutputStream.h>
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2017-07-11 21:41:37 +00:00
|
|
|
void PrettySpaceBlockOutputStream::write(const Block & block)
|
2011-11-28 04:05:53 +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;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t rows = block.rows();
|
|
|
|
size_t columns = block.columns();
|
|
|
|
|
2017-07-11 21:41:37 +00:00
|
|
|
WidthsPerColumn widths;
|
|
|
|
Widths max_widths;
|
|
|
|
Widths name_widths;
|
|
|
|
calculateWidths(block, widths, max_widths, name_widths);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// Do not align on too long values.
|
|
|
|
if (terminal_width > 80)
|
|
|
|
for (size_t i = 0; i < columns; ++i)
|
|
|
|
if (max_widths[i] > terminal_width / 2)
|
|
|
|
max_widths[i] = terminal_width / 2;
|
|
|
|
|
|
|
|
/// Names
|
|
|
|
for (size_t i = 0; i < columns; ++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())
|
|
|
|
{
|
2017-09-01 17:21:03 +00:00
|
|
|
for (ssize_t k = 0; k < std::max(static_cast<ssize_t>(0), static_cast<ssize_t>(max_widths[i] - name_widths[i])); ++k)
|
2017-04-01 07:20:54 +00:00
|
|
|
writeChar(' ', 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);
|
|
|
|
|
2017-09-01 17:21:03 +00:00
|
|
|
for (ssize_t k = 0; k < std::max(static_cast<ssize_t>(0), static_cast<ssize_t>(max_widths[i] - name_widths[i])); ++k)
|
2017-04-01 07:20:54 +00:00
|
|
|
writeChar(' ', ostr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
writeCString("\n\n", ostr);
|
|
|
|
|
|
|
|
for (size_t i = 0; i < rows && total_rows + i < max_rows; ++i)
|
|
|
|
{
|
|
|
|
for (size_t j = 0; j < columns; ++j)
|
|
|
|
{
|
|
|
|
if (j != 0)
|
|
|
|
writeCString(" ", ostr);
|
|
|
|
|
2017-07-11 21:41:37 +00:00
|
|
|
writeValueWithPadding(block.getByPosition(j), i, widths[j].empty() ? max_widths[j] : widths[j][i], max_widths[j]);
|
2017-04-01 07:20:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
writeChar('\n', ostr);
|
|
|
|
}
|
|
|
|
|
|
|
|
total_rows += rows;
|
2011-11-28 04:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PrettySpaceBlockOutputStream::writeSuffix()
|
|
|
|
{
|
2017-04-01 07:20:54 +00:00
|
|
|
if (total_rows >= max_rows)
|
|
|
|
{
|
|
|
|
writeCString("\nShowed first ", ostr);
|
|
|
|
writeIntText(max_rows, ostr);
|
|
|
|
writeCString(".\n", ostr);
|
|
|
|
}
|
|
|
|
|
|
|
|
total_rows = 0;
|
|
|
|
writeTotals();
|
|
|
|
writeExtremes();
|
2011-11-28 04:05:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|