2019-02-19 18:41:18 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <Core/Block.h>
|
|
|
|
#include <Processors/Formats/IOutputFormat.h>
|
|
|
|
#include <Formats/FormatSettings.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class WriteBuffer;
|
|
|
|
class Context;
|
|
|
|
|
|
|
|
|
|
|
|
/** Prints the result in the form of beautiful tables.
|
|
|
|
*/
|
|
|
|
class PrettyBlockOutputFormat : public IOutputFormat
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// no_escapes - do not use ANSI escape sequences - to display in the browser, not in the console.
|
2019-08-03 11:02:40 +00:00
|
|
|
PrettyBlockOutputFormat(WriteBuffer & out_, const Block & header_, const FormatSettings & format_settings_);
|
2019-02-19 18:41:18 +00:00
|
|
|
|
|
|
|
String getName() const override { return "PrettyBlockOutputFormat"; }
|
|
|
|
|
|
|
|
void consume(Chunk) override;
|
|
|
|
void consumeTotals(Chunk) override;
|
|
|
|
void consumeExtremes(Chunk) override;
|
|
|
|
|
|
|
|
void finalize() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
size_t total_rows = 0;
|
|
|
|
size_t terminal_width = 0;
|
|
|
|
bool suffix_written = false;
|
|
|
|
|
|
|
|
const FormatSettings format_settings;
|
|
|
|
|
|
|
|
using Widths = PODArray<size_t>;
|
|
|
|
using WidthsPerColumn = std::vector<Widths>;
|
|
|
|
|
|
|
|
virtual void write(const Chunk & chunk, PortKind port_kind);
|
|
|
|
virtual void writeSuffix();
|
|
|
|
|
|
|
|
|
2020-08-05 22:43:23 +00:00
|
|
|
virtual void writeSuffixIfNot()
|
2019-02-19 18:41:18 +00:00
|
|
|
{
|
|
|
|
if (!suffix_written)
|
|
|
|
writeSuffix();
|
|
|
|
|
|
|
|
suffix_written = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void calculateWidths(
|
|
|
|
const Block & header, const Chunk & chunk,
|
2020-06-02 13:53:34 +00:00
|
|
|
WidthsPerColumn & widths, Widths & max_padded_widths, Widths & name_widths);
|
2019-02-19 18:41:18 +00:00
|
|
|
|
|
|
|
void writeValueWithPadding(
|
|
|
|
const IColumn & column, const IDataType & type, size_t row_num, size_t value_width, size_t pad_to_width);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|