ClickHouse/dbms/src/Processors/ISource.cpp

48 lines
779 B
C++
Raw Normal View History

#include <Processors/ISource.h>
namespace DB
{
ISource::ISource(Block header)
: IProcessor({}, {std::move(header)}), output(outputs.front())
{
}
ISource::Status ISource::prepare()
{
if (finished)
{
2019-02-07 18:51:53 +00:00
output.finish();
return Status::Finished;
}
2019-02-07 18:51:53 +00:00
/// Check can output.
if (output.isFinished())
return Status::Finished;
if (!output.canPush())
return Status::PortFull;
2019-02-07 18:51:53 +00:00
if (!has_input)
return Status::Ready;
2019-02-07 18:51:53 +00:00
output.push(std::move(current_block));
has_input = false;
2019-02-07 18:51:53 +00:00
/// Now, we pushed to output, and it must be full.
return Status::PortFull;
}
void ISource::work()
{
current_block = generate();
if (!current_block)
finished = true;
2019-02-07 18:51:53 +00:00
else
has_input = true;
}
}