ClickHouse/dbms/include/DB/DataStreams/PrettyBlockOutputStream.h
2016-05-28 13:35:44 +03:00

48 lines
1.3 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <DB/DataStreams/IBlockOutputStream.h>
#define PRETTY_FORMAT_DEFAULT_MAX_ROWS 10000
namespace DB
{
/** Выводит результат в виде красивых таблиц.
*/
class PrettyBlockOutputStream : public IBlockOutputStream
{
public:
/// no_escapes - не использовать ANSI escape sequences - для отображения в браузере, а не в консоли.
PrettyBlockOutputStream(WriteBuffer & ostr_, bool no_escapes_ = false, size_t max_rows_ = PRETTY_FORMAT_DEFAULT_MAX_ROWS);
void write(const Block & block) override;
void writeSuffix() override;
void flush() override { ostr.next(); }
void setTotals(const Block & totals_) override { totals = totals_; }
void setExtremes(const Block & extremes_) override { extremes = extremes_; }
protected:
void writeTotals();
void writeExtremes();
using Widths_t = std::vector<size_t>;
/// Вычислить видимую (при выводе на консоль с кодировкой UTF-8) ширину значений и имён столбцов.
void calculateWidths(Block & block, Widths_t & max_widths, Widths_t & name_widths);
WriteBuffer & ostr;
size_t max_rows;
size_t total_rows;
size_t terminal_width;
bool no_escapes;
Block totals;
Block extremes;
};
}