ClickHouse/dbms/src/Processors/IAccumulatingTransform.cpp

76 lines
1.5 KiB
C++
Raw Normal View History

#include <Processors/IAccumulatingTransform.h>
namespace DB
{
IAccumulatingTransform::IAccumulatingTransform(Block input_header, Block output_header)
: IProcessor({std::move(input_header)}, {std::move(output_header)}),
input(inputs.front()), output(outputs.front())
{
}
IAccumulatingTransform::Status IAccumulatingTransform::prepare()
{
2019-02-07 18:51:53 +00:00
/// Check can output.
if (output.isFinished())
{
input.close();
return Status::Finished;
}
2019-02-07 18:51:53 +00:00
if (!output.canPush())
{
2019-02-07 18:51:53 +00:00
input.setNotNeeded();
return Status::PortFull;
}
2019-02-07 18:51:53 +00:00
/// Output if has data.
if (current_output_block)
output.push(std::move(current_output_block));
if (finished_generate)
{
2019-02-07 18:51:53 +00:00
output.finish();
return Status::Finished;
}
2019-02-07 18:51:53 +00:00
/// Check can input.
if (!has_input)
{
2019-02-07 18:51:53 +00:00
/// Generate output block.
if (input.isFinished())
{
finished_input = true;
return Status::Ready;
}
2019-02-07 18:51:53 +00:00
input.setNeeded();
if (!input.hasData())
return Status::NeedData;
current_input_block = input.pull();
has_input = true;
}
2019-02-07 18:51:53 +00:00
return Status::Ready;
}
void IAccumulatingTransform::work()
{
2019-02-07 18:51:53 +00:00
if (!finished_input)
{
consume(std::move(current_input_block));
2019-02-07 18:51:53 +00:00
has_input = false;
}
else
{
current_output_block = generate();
if (!current_output_block)
2019-02-07 18:51:53 +00:00
finished_generate = true;
}
}
}