ClickHouse/src/Processors/ISimpleTransform.cpp

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

111 lines
2.4 KiB
C++
Raw Normal View History

#include <Processors/ISimpleTransform.h>
namespace DB
{
2019-08-03 11:02:40 +00:00
ISimpleTransform::ISimpleTransform(Block input_header_, Block output_header_, bool skip_empty_chunks_)
: IProcessor({std::move(input_header_)}, {std::move(output_header_)})
, input(inputs.front())
, output(outputs.front())
2019-08-03 11:02:40 +00:00
, skip_empty_chunks(skip_empty_chunks_)
{
}
ISimpleTransform::Status ISimpleTransform::prepare()
{
2019-02-07 18:51:53 +00:00
/// Check can output.
2019-02-07 18:51:53 +00:00
if (output.isFinished())
{
2019-02-07 18:51:53 +00:00
input.close();
return Status::Finished;
}
2019-02-07 18:51:53 +00:00
if (!output.canPush())
{
2019-02-07 18:51:53 +00:00
input.setNotNeeded();
return Status::PortFull;
}
/// Output if has data.
2020-04-22 13:52:07 +00:00
if (has_output)
2019-02-07 18:51:53 +00:00
{
2020-04-22 13:52:07 +00:00
output.pushData(std::move(output_data));
has_output = false;
2020-01-14 17:21:59 +00:00
if (!no_more_data_needed)
return Status::PortFull;
}
2019-03-25 16:58:59 +00:00
/// Stop if don't need more data.
if (no_more_data_needed)
{
input.close();
output.finish();
return Status::Finished;
}
2019-02-07 18:51:53 +00:00
/// Check can input.
if (!has_input)
{
2019-02-07 18:51:53 +00:00
if (input.isFinished())
{
output.finish();
return Status::Finished;
}
2020-04-22 13:52:07 +00:00
input.setNeeded();
2019-02-07 18:51:53 +00:00
if (!input.hasData())
return Status::NeedData;
2020-04-22 13:52:07 +00:00
input_data = input.pullData(set_input_not_needed_after_read);
2019-02-07 18:51:53 +00:00
has_input = true;
2020-04-22 13:52:07 +00:00
if (input_data.exception)
/// No more data needed. Exception will be thrown (or swallowed) later.
input.setNotNeeded();
}
2019-02-07 18:51:53 +00:00
/// Now transform.
return Status::Ready;
}
void ISimpleTransform::work()
{
2020-04-22 13:52:07 +00:00
if (input_data.exception)
{
/// Skip transform in case of exception.
output_data = std::move(input_data);
has_input = false;
has_output = true;
return;
2020-04-22 13:52:07 +00:00
}
try
{
2020-04-22 13:52:07 +00:00
transform(input_data.chunk, output_data.chunk);
}
catch (DB::Exception &)
{
2020-04-22 13:52:07 +00:00
output_data.exception = std::current_exception();
has_output = true;
has_input = false;
return;
}
2020-01-22 07:46:14 +00:00
has_input = !needInputData();
2020-04-22 13:52:07 +00:00
if (!skip_empty_chunks || output_data.chunk)
has_output = true;
2020-04-22 13:52:07 +00:00
if (has_output && !output_data.chunk && getOutputPort().getHeader())
/// Support invariant that chunks must have the same number of columns as header.
2020-04-22 13:52:07 +00:00
output_data.chunk = Chunk(getOutputPort().getHeader().cloneEmpty().getColumns(), 0);
}
}