ClickHouse/src/Processors/IInflatingTransform.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

94 lines
1.8 KiB
C++
Raw Normal View History

2019-03-19 11:08:33 +00:00
#include <Processors/IInflatingTransform.h>
namespace DB
{
2020-02-25 18:10:48 +00:00
namespace ErrorCodes
{
extern const int LOGICAL_ERROR;
}
2019-03-19 11:08:33 +00:00
IInflatingTransform::IInflatingTransform(Block input_header, Block output_header)
: IProcessor({std::move(input_header)}, {std::move(output_header)})
, input(inputs.front()), output(outputs.front())
{
}
IInflatingTransform::Status IInflatingTransform::prepare()
{
/// Check can output.
if (output.isFinished())
{
input.close();
return Status::Finished;
}
if (!output.canPush())
{
input.setNotNeeded();
return Status::PortFull;
}
/// Output if has data.
if (generated)
{
output.push(std::move(current_chunk));
generated = false;
}
if (can_generate)
return Status::Ready;
/// Check can input.
if (!has_input)
{
if (input.isFinished())
{
if (is_finished)
{
output.finish();
return Status::Finished;
}
is_finished = true;
return Status::Ready;
2019-03-19 11:08:33 +00:00
}
input.setNeeded();
if (!input.hasData())
return Status::NeedData;
current_chunk = input.pull();
has_input = true;
}
/// Now transform.
return Status::Ready;
}
void IInflatingTransform::work()
{
if (can_generate)
{
if (generated)
throw Exception(ErrorCodes::LOGICAL_ERROR, "IInflatingTransform cannot consume chunk because it already was generated");
2019-03-19 11:08:33 +00:00
current_chunk = generate();
generated = true;
can_generate = canGenerate(is_finished);
2019-03-19 11:08:33 +00:00
}
else
{
if (has_input)
{
consume(std::move(current_chunk));
has_input = false;
}
2019-03-19 11:08:33 +00:00
can_generate = canGenerate(is_finished);
2019-03-19 11:08:33 +00:00
}
}
}