2018-05-23 20:19:33 +00:00
|
|
|
#include <Processors/ISink.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ISink::ISink(Block header)
|
|
|
|
: IProcessor({std::move(header)}, {}), input(inputs.front())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ISink::Status ISink::prepare()
|
|
|
|
{
|
2021-07-26 14:47:29 +00:00
|
|
|
if (!was_on_start_called)
|
|
|
|
return Status::Ready;
|
|
|
|
|
2019-02-07 18:51:53 +00:00
|
|
|
if (has_input)
|
2018-05-23 20:19:33 +00:00
|
|
|
return Status::Ready;
|
|
|
|
|
|
|
|
if (input.isFinished())
|
2020-02-19 15:09:32 +00:00
|
|
|
{
|
2021-07-23 14:25:35 +00:00
|
|
|
if (!was_on_finish_called)
|
|
|
|
return Status::Ready;
|
|
|
|
|
2018-05-23 20:19:33 +00:00
|
|
|
return Status::Finished;
|
2020-02-19 15:09:32 +00:00
|
|
|
}
|
2018-05-23 20:19:33 +00:00
|
|
|
|
|
|
|
input.setNeeded();
|
2019-02-07 18:51:53 +00:00
|
|
|
if (!input.hasData())
|
|
|
|
return Status::NeedData;
|
|
|
|
|
2020-10-14 12:51:38 +00:00
|
|
|
current_chunk = input.pull(true);
|
2019-02-07 18:51:53 +00:00
|
|
|
has_input = true;
|
|
|
|
return Status::Ready;
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ISink::work()
|
|
|
|
{
|
2021-07-26 14:47:29 +00:00
|
|
|
if (!was_on_start_called)
|
|
|
|
{
|
|
|
|
was_on_start_called = true;
|
|
|
|
onStart();
|
|
|
|
}
|
|
|
|
else if (has_input)
|
2021-07-23 14:25:35 +00:00
|
|
|
{
|
|
|
|
has_input = false;
|
2021-07-26 14:47:29 +00:00
|
|
|
consume(std::move(current_chunk));
|
2021-07-23 14:25:35 +00:00
|
|
|
}
|
2021-07-26 14:47:29 +00:00
|
|
|
else if (!was_on_finish_called)
|
2021-07-23 14:25:35 +00:00
|
|
|
{
|
|
|
|
was_on_finish_called = true;
|
2021-07-26 14:47:29 +00:00
|
|
|
onFinish();
|
2021-07-23 14:25:35 +00:00
|
|
|
}
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|