2018-05-23 20:19:33 +00:00
|
|
|
#include <Processors/ISource.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ISource::ISource(Block header)
|
|
|
|
: IProcessor({}, {std::move(header)}), output(outputs.front())
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ISource::Status ISource::prepare()
|
|
|
|
{
|
2020-01-27 18:09:20 +00:00
|
|
|
if (finished || isCancelled())
|
2018-05-24 02:52:21 +00:00
|
|
|
{
|
2019-02-07 18:51:53 +00:00
|
|
|
output.finish();
|
2018-05-23 20:19:33 +00:00
|
|
|
return Status::Finished;
|
2018-05-24 02:52:21 +00:00
|
|
|
}
|
2018-05-23 20:19:33 +00:00
|
|
|
|
2019-02-07 18:51:53 +00:00
|
|
|
/// Check can output.
|
|
|
|
if (output.isFinished())
|
|
|
|
return Status::Finished;
|
|
|
|
|
|
|
|
if (!output.canPush())
|
2018-05-23 20:19:33 +00:00
|
|
|
return Status::PortFull;
|
|
|
|
|
2019-02-07 18:51:53 +00:00
|
|
|
if (!has_input)
|
|
|
|
return Status::Ready;
|
2018-05-23 20:19:33 +00:00
|
|
|
|
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;
|
2018-05-23 20:19:33 +00:00
|
|
|
|
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;
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ISource::work()
|
|
|
|
{
|
2019-05-14 09:50:04 +00:00
|
|
|
try
|
2019-04-29 18:43:50 +00:00
|
|
|
{
|
2019-06-19 18:30:02 +00:00
|
|
|
current_chunk.chunk = generate();
|
2020-01-27 10:59:54 +00:00
|
|
|
if (!current_chunk.chunk || isCancelled())
|
2019-04-29 18:43:50 +00:00
|
|
|
finished = true;
|
|
|
|
else
|
|
|
|
has_input = true;
|
|
|
|
}
|
2019-05-14 09:50:04 +00:00
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
finished = true;
|
|
|
|
throw;
|
|
|
|
}
|
2019-04-30 09:43:51 +00:00
|
|
|
// {
|
|
|
|
// current_chunk = std::current_exception();
|
|
|
|
// has_input = true;
|
|
|
|
// got_exception = true;
|
|
|
|
// }
|
2018-05-23 20:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|