2018-05-23 20:19:33 +00:00
|
|
|
#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;
|
|
|
|
}
|
2018-05-23 20:19:33 +00:00
|
|
|
|
2019-02-07 18:51:53 +00:00
|
|
|
if (!output.canPush())
|
2018-05-23 20:19:33 +00:00
|
|
|
{
|
2019-02-07 18:51:53 +00:00
|
|
|
input.setNotNeeded();
|
|
|
|
return Status::PortFull;
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 18:51:53 +00:00
|
|
|
/// Output if has data.
|
2019-02-18 16:36:07 +00:00
|
|
|
if (current_output_chunk)
|
|
|
|
output.push(std::move(current_output_chunk));
|
2019-02-07 18:51:53 +00:00
|
|
|
|
|
|
|
if (finished_generate)
|
2018-05-23 20:19:33 +00:00
|
|
|
{
|
2019-02-07 18:51:53 +00:00
|
|
|
output.finish();
|
|
|
|
return Status::Finished;
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
|
2019-03-04 14:56:09 +00:00
|
|
|
/// Generate output block.
|
|
|
|
if (input.isFinished())
|
|
|
|
{
|
|
|
|
finished_input = true;
|
|
|
|
return Status::Ready;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Close input if flag was set manually.
|
|
|
|
if (finished_input)
|
|
|
|
{
|
|
|
|
input.close();
|
|
|
|
return Status::Ready;
|
|
|
|
}
|
|
|
|
|
2019-02-07 18:51:53 +00:00
|
|
|
/// Check can input.
|
|
|
|
if (!has_input)
|
2018-05-23 20:19:33 +00:00
|
|
|
{
|
2019-02-07 18:51:53 +00:00
|
|
|
input.setNeeded();
|
|
|
|
if (!input.hasData())
|
|
|
|
return Status::NeedData;
|
|
|
|
|
2019-02-18 16:36:07 +00:00
|
|
|
current_input_chunk = input.pull();
|
2019-02-07 18:51:53 +00:00
|
|
|
has_input = true;
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
|
2019-02-07 18:51:53 +00:00
|
|
|
return Status::Ready;
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IAccumulatingTransform::work()
|
|
|
|
{
|
2019-02-07 18:51:53 +00:00
|
|
|
if (!finished_input)
|
2018-05-23 20:19:33 +00:00
|
|
|
{
|
2019-02-18 16:36:07 +00:00
|
|
|
consume(std::move(current_input_chunk));
|
2019-02-07 18:51:53 +00:00
|
|
|
has_input = false;
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-18 16:36:07 +00:00
|
|
|
current_output_chunk = generate();
|
|
|
|
if (!current_output_chunk)
|
2019-02-07 18:51:53 +00:00
|
|
|
finished_generate = true;
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-26 18:40:08 +00:00
|
|
|
void IAccumulatingTransform::setReadyChunk(Chunk chunk)
|
|
|
|
{
|
|
|
|
if (current_output_chunk)
|
|
|
|
throw Exception("IAccumulatingTransform already has input. Cannot set another chunk. "
|
|
|
|
"Probably, setReadyChunk method was called twose per consume().", ErrorCodes::LOGICAL_ERROR);
|
|
|
|
|
|
|
|
current_output_chunk = std::move(chunk);
|
|
|
|
}
|
|
|
|
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
|