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