2011-11-07 01:15:37 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <DataStreams/IBlockOutputStream.h>
|
2011-11-07 01:15:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-08-13 01:57:35 +00:00
|
|
|
class WriteBuffer;
|
2016-12-30 00:15:50 +00:00
|
|
|
class Context;
|
2016-08-13 01:57:35 +00:00
|
|
|
|
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/** Prints the result in the form of beautiful tables.
|
2011-11-07 01:15:37 +00:00
|
|
|
*/
|
|
|
|
class PrettyBlockOutputStream : public IBlockOutputStream
|
|
|
|
{
|
|
|
|
public:
|
2017-05-13 22:19:04 +00:00
|
|
|
/// no_escapes - do not use ANSI escape sequences - to display in the browser, not in the console.
|
2017-04-01 07:20:54 +00:00
|
|
|
PrettyBlockOutputStream(WriteBuffer & ostr_, bool no_escapes_, size_t max_rows_, const Context & context_);
|
2011-11-07 01:15:37 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void write(const Block & block) override;
|
|
|
|
void writeSuffix() override;
|
2014-08-14 20:27:41 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void flush() override;
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
void setTotals(const Block & totals_) override { totals = totals_; }
|
|
|
|
void setExtremes(const Block & extremes_) override { extremes = extremes_; }
|
2014-03-02 19:16:45 +00:00
|
|
|
|
2011-11-28 04:05:53 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
void writeTotals();
|
|
|
|
void writeExtremes();
|
2014-03-02 19:16:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
WriteBuffer & ostr;
|
|
|
|
size_t max_rows;
|
|
|
|
size_t total_rows = 0;
|
|
|
|
size_t terminal_width = 0;
|
2012-06-25 05:07:34 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
bool no_escapes;
|
2014-03-02 19:16:45 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Block totals;
|
|
|
|
Block extremes;
|
2016-12-30 00:15:50 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
const Context & context;
|
2017-07-11 21:41:37 +00:00
|
|
|
|
|
|
|
using Widths = PODArray<size_t>;
|
|
|
|
using WidthsPerColumn = PODArray<Widths>;
|
|
|
|
|
|
|
|
static void calculateWidths(const Block & block, WidthsPerColumn & widths, Widths & max_widths, Widths & name_widths);
|
|
|
|
void writeValueWithPadding(const ColumnWithTypeAndName & elem, size_t row_num, size_t value_width, size_t pad_to_width);
|
2011-11-07 01:15:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|