2018-05-24 02:39:22 +00:00
|
|
|
#include <Processors/ForkProcessor.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
ForkProcessor::Status ForkProcessor::prepare()
|
|
|
|
{
|
|
|
|
auto & input = inputs[0];
|
|
|
|
|
|
|
|
bool all_outputs_unneeded = true;
|
|
|
|
|
|
|
|
for (const auto & output : outputs)
|
|
|
|
{
|
|
|
|
if (output.isNeeded())
|
|
|
|
{
|
|
|
|
all_outputs_unneeded = false;
|
|
|
|
if (output.hasData())
|
|
|
|
return Status::PortFull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (all_outputs_unneeded)
|
|
|
|
{
|
|
|
|
input.setNotNeeded();
|
|
|
|
return Status::Unneeded;
|
|
|
|
}
|
|
|
|
|
|
|
|
input.setNeeded();
|
|
|
|
|
|
|
|
if (!input.hasData())
|
|
|
|
{
|
|
|
|
if (input.isFinished())
|
|
|
|
{
|
|
|
|
input.setNotNeeded();
|
2018-05-24 02:52:21 +00:00
|
|
|
for (auto & output : outputs)
|
|
|
|
output.setFinished();
|
2018-05-24 02:39:22 +00:00
|
|
|
return Status::Finished;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return Status::NeedData;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto data = input.pull();
|
|
|
|
|
|
|
|
for (auto & output : outputs)
|
|
|
|
if (output.isNeeded())
|
|
|
|
output.push(data);
|
|
|
|
|
|
|
|
return Status::NeedData;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|