ClickHouse/dbms/Processors/Formats/IOutputFormat.cpp

82 lines
1.5 KiB
C++
Raw Normal View History

#include <Processors/Formats/IOutputFormat.h>
2019-02-19 18:41:18 +00:00
#include <IO/WriteBuffer.h>
namespace DB
{
2019-08-03 11:02:40 +00:00
IOutputFormat::IOutputFormat(const Block & header_, WriteBuffer & out_)
: IProcessor({header_, header_, header_}, {}), out(out_)
{
}
IOutputFormat::Status IOutputFormat::prepare()
{
2019-02-07 18:51:53 +00:00
if (has_input)
return Status::Ready;
for (auto kind : {Main, Totals, Extremes})
{
auto & input = getPort(kind);
2019-02-07 18:51:53 +00:00
if (kind != Main && !input.isConnected())
continue;
2019-02-07 18:51:53 +00:00
if (input.isFinished())
continue;
input.setNeeded();
if (!input.hasData())
return Status::NeedData;
2019-02-07 18:51:53 +00:00
current_chunk = input.pull();
2019-02-07 18:51:53 +00:00
current_block_kind = kind;
has_input = true;
return Status::Ready;
}
2019-02-19 18:41:18 +00:00
finished = true;
if (!finalized)
return Status::Ready;
return Status::Finished;
}
void IOutputFormat::work()
{
2019-02-19 18:41:18 +00:00
if (finished && !finalized)
{
if (rows_before_limit_counter && rows_before_limit_counter->hasAppliedLimit())
setRowsBeforeLimit(rows_before_limit_counter->get());
2019-02-19 18:41:18 +00:00
finalize();
finalized = true;
return;
}
switch (current_block_kind)
{
case Main:
consume(std::move(current_chunk));
break;
case Totals:
consumeTotals(std::move(current_chunk));
break;
case Extremes:
consumeExtremes(std::move(current_chunk));
break;
}
2019-02-07 18:51:53 +00:00
has_input = false;
}
2019-02-19 18:41:18 +00:00
void IOutputFormat::flush()
{
out.next();
}
}