2011-11-28 04:05:53 +00:00
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
#include <DB/DataStreams/PrettyCompactBlockOutputStream.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
void PrettyCompactBlockOutputStream::writeHeader(
|
|
|
|
|
const Block & block,
|
|
|
|
|
const Widths_t & max_widths,
|
|
|
|
|
const Widths_t & name_widths)
|
2011-11-28 04:05:53 +00:00
|
|
|
|
{
|
|
|
|
|
/// Имена
|
2013-05-15 22:58:57 +00:00
|
|
|
|
writeCString("┌─", ostr);
|
2013-06-18 09:56:11 +00:00
|
|
|
|
for (size_t i = 0; i < max_widths.size(); ++i)
|
2011-11-28 04:05:53 +00:00
|
|
|
|
{
|
|
|
|
|
if (i != 0)
|
2013-05-15 22:58:57 +00:00
|
|
|
|
writeCString("─┬─", ostr);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
2015-07-17 01:27:35 +00:00
|
|
|
|
const ColumnWithTypeAndName & col = block.getByPosition(i);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
|
|
|
|
if (col.type->isNumeric())
|
|
|
|
|
{
|
|
|
|
|
for (size_t k = 0; k < max_widths[i] - name_widths[i]; ++k)
|
2013-05-15 22:58:57 +00:00
|
|
|
|
writeCString("─", ostr);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
2012-06-25 05:07:34 +00:00
|
|
|
|
if (!no_escapes)
|
2014-08-15 00:08:15 +00:00
|
|
|
|
writeCString("\033[1m", ostr);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
writeEscapedString(col.name, ostr);
|
2012-06-25 05:07:34 +00:00
|
|
|
|
if (!no_escapes)
|
2013-05-15 22:58:57 +00:00
|
|
|
|
writeCString("\033[0m", ostr);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-06-25 05:07:34 +00:00
|
|
|
|
if (!no_escapes)
|
2014-08-15 00:08:15 +00:00
|
|
|
|
writeCString("\033[1m", ostr);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
writeEscapedString(col.name, ostr);
|
2012-06-25 05:07:34 +00:00
|
|
|
|
if (!no_escapes)
|
2013-05-15 22:58:57 +00:00
|
|
|
|
writeCString("\033[0m", ostr);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
|
|
|
|
for (size_t k = 0; k < max_widths[i] - name_widths[i]; ++k)
|
2013-05-15 22:58:57 +00:00
|
|
|
|
writeCString("─", ostr);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-05-15 22:58:57 +00:00
|
|
|
|
writeCString("─┐\n", ostr);
|
2013-06-18 09:56:11 +00:00
|
|
|
|
}
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
void PrettyCompactBlockOutputStream::writeBottom(const Widths_t & max_widths)
|
|
|
|
|
{
|
|
|
|
|
/// Создадим разделители
|
|
|
|
|
std::stringstream bottom_separator;
|
|
|
|
|
|
|
|
|
|
bottom_separator << "└";
|
|
|
|
|
for (size_t i = 0; i < max_widths.size(); ++i)
|
2011-11-28 04:05:53 +00:00
|
|
|
|
{
|
2013-06-18 09:56:11 +00:00
|
|
|
|
if (i != 0)
|
|
|
|
|
bottom_separator << "┴";
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
for (size_t j = 0; j < max_widths[i] + 2; ++j)
|
|
|
|
|
bottom_separator << "─";
|
|
|
|
|
}
|
|
|
|
|
bottom_separator << "┘\n";
|
|
|
|
|
|
|
|
|
|
writeString(bottom_separator.str(), ostr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrettyCompactBlockOutputStream::writeRow(
|
|
|
|
|
size_t row_id,
|
|
|
|
|
const Block & block,
|
|
|
|
|
const Widths_t & max_widths,
|
|
|
|
|
const Widths_t & name_widths)
|
|
|
|
|
{
|
|
|
|
|
size_t columns = max_widths.size();
|
2014-08-15 00:08:15 +00:00
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
writeCString("│ ", ostr);
|
|
|
|
|
|
|
|
|
|
for (size_t j = 0; j < columns; ++j)
|
|
|
|
|
{
|
|
|
|
|
if (j != 0)
|
|
|
|
|
writeCString(" │ ", ostr);
|
|
|
|
|
|
2015-07-17 01:27:35 +00:00
|
|
|
|
const ColumnWithTypeAndName & col = block.getByPosition(j);
|
2013-06-18 09:56:11 +00:00
|
|
|
|
|
|
|
|
|
if (col.type->isNumeric())
|
2011-11-28 04:05:53 +00:00
|
|
|
|
{
|
2013-06-18 09:56:11 +00:00
|
|
|
|
size_t width = get<UInt64>((*block.getByPosition(columns + j).column)[row_id]);
|
|
|
|
|
for (size_t k = 0; k < max_widths[j] - width; ++k)
|
|
|
|
|
writeChar(' ', ostr);
|
2014-08-15 00:08:15 +00:00
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
col.type->serializeTextEscaped((*col.column)[row_id], ostr);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
}
|
2013-06-18 09:56:11 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
col.type->serializeTextEscaped((*col.column)[row_id], ostr);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
size_t width = get<UInt64>((*block.getByPosition(columns + j).column)[row_id]);
|
|
|
|
|
for (size_t k = 0; k < max_widths[j] - width; ++k)
|
|
|
|
|
writeChar(' ', ostr);
|
|
|
|
|
}
|
2011-11-28 04:05:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
writeCString(" │\n", ostr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PrettyCompactBlockOutputStream::write(const Block & block_)
|
|
|
|
|
{
|
|
|
|
|
if (total_rows >= max_rows)
|
|
|
|
|
{
|
|
|
|
|
total_rows += block_.rows();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-08-15 00:08:15 +00:00
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
/// Будем вставлять сюда столбцы с вычисленными значениями видимых длин.
|
|
|
|
|
Block block = block_;
|
2014-08-15 00:08:15 +00:00
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
size_t rows = block.rows();
|
|
|
|
|
|
|
|
|
|
Widths_t max_widths;
|
|
|
|
|
Widths_t name_widths;
|
|
|
|
|
calculateWidths(block, max_widths, name_widths);
|
2014-08-15 00:08:15 +00:00
|
|
|
|
|
2013-06-18 09:56:11 +00:00
|
|
|
|
writeHeader(block, max_widths, name_widths);
|
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < rows && total_rows + i < max_rows; ++i)
|
|
|
|
|
writeRow(i, block, max_widths, name_widths);
|
|
|
|
|
|
|
|
|
|
writeBottom(max_widths);
|
2011-11-28 04:05:53 +00:00
|
|
|
|
|
|
|
|
|
total_rows += rows;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|