ClickHouse/dbms/include/DB/DataStreams/PrettyBlockOutputStream.h

52 lines
1.3 KiB
C++
Raw Normal View History

2011-11-07 01:15:37 +00:00
#pragma once
#include <DB/DataStreams/IBlockOutputStream.h>
namespace DB
{
2016-08-13 01:57:35 +00:00
class WriteBuffer;
class Context;
2016-08-13 01:57:35 +00:00
2011-11-07 01:15:37 +00:00
/** Выводит результат в виде красивых таблиц.
*/
class PrettyBlockOutputStream : public IBlockOutputStream
{
public:
2012-06-25 05:07:34 +00:00
/// no_escapes - не использовать ANSI escape sequences - для отображения в браузере, а не в консоли.
PrettyBlockOutputStream(WriteBuffer & ostr_, bool no_escapes_, size_t max_rows_, const Context & context_);
2011-11-07 01:15:37 +00:00
void write(const Block & block) override;
void writeSuffix() override;
2016-08-13 01:57:35 +00:00
void flush() override;
void setTotals(const Block & totals_) override { totals = totals_; }
void setExtremes(const Block & extremes_) override { extremes = extremes_; }
2011-11-28 04:05:53 +00:00
protected:
void writeTotals();
void writeExtremes();
using Widths_t = std::vector<size_t>;
2011-11-28 04:05:53 +00:00
/// Вычислить видимую (при выводе на консоль с кодировкой UTF-8) ширину значений и имён столбцов.
void calculateWidths(Block & block, Widths_t & max_widths, Widths_t & name_widths);
2011-11-07 01:15:37 +00:00
WriteBuffer & ostr;
2011-11-07 04:51:37 +00:00
size_t max_rows;
size_t total_rows = 0;
size_t terminal_width = 0;
2012-06-25 05:07:34 +00:00
bool no_escapes;
Block totals;
Block extremes;
const Context & context;
2011-11-07 01:15:37 +00:00
};
}