ClickHouse/dbms/src/Processors/ISource.cpp

64 lines
1.1 KiB
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-04-29 18:43:50 +00:00
output.pushData(std::move(current_chunk));
2019-02-07 18:51:53 +00:00
has_input = false;
2019-04-29 18:43:50 +00:00
if (got_exception)
{
finished = true;
output.finish();
return Status::Finished;
}
2019-02-07 18:51:53 +00:00
/// Now, we pushed to output, and it must be full.
return Status::PortFull;
}
void ISource::work()
{
2019-04-29 18:43:50 +00:00
try
{
current_chunk = generate();
if (!std::get<Chunk>(current_chunk))
finished = true;
else
has_input = true;
}
catch (Exception &)
{
current_chunk = std::current_exception();
2019-02-07 18:51:53 +00:00
has_input = true;
2019-04-29 18:43:50 +00:00
got_exception = true;
}
}
}