ClickHouse/dbms/src/Processors/Formats/IOutputFormat.h
2019-02-15 19:18:19 +03:00

55 lines
1.3 KiB
C++

#pragma once
#include <string>
#include <Processors/IProcessor.h>
namespace DB
{
class WriteBuffer;
/** Output format have three inputs and no outputs. It writes data from WriteBuffer.
*
* First input is for main resultset, second is for "totals" and third is for "extremes".
* It's not necessarily to connect "totals" or "extremes" ports (they may remain dangling).
*
* Data from input ports are pulled in order: first, from main input, then totals, then extremes.
*
* By default, data for "totals" and "extremes" is ignored.
*/
class IOutputFormat : public IProcessor
{
public:
enum PortKind { Main = 0, Totals = 1, Extremes = 2 };
protected:
WriteBuffer & out;
Block current_block;
PortKind current_block_kind;
bool has_input = false;
virtual void consume(Block) = 0;
virtual void consumeTotals(Block) {}
virtual void consumeExtremes(Block) {}
public:
IOutputFormat(Block header, WriteBuffer & out);
Status prepare() override;
void work() override;
void flush();
/** Content-Type to set when sending HTTP response.
*/
virtual std::string getContentType() const { return "text/plain; charset=UTF-8"; }
/// TODO onProgress, rows_before_limit_at_least
InputPort & getPort(PortKind kind) { return inputs[kind]; }
};
}