ClickHouse/dbms/DataStreams/ExpressionBlockInputStream.cpp

73 lines
1.5 KiB
C++
Raw Normal View History

#include <Interpreters/ExpressionActions.h>
#include <DataStreams/ExpressionBlockInputStream.h>
2016-01-13 00:32:59 +00:00
namespace DB
{
ExpressionBlockInputStream::ExpressionBlockInputStream(const BlockInputStreamPtr & input, const ExpressionActionsPtr & expression_)
: expression(expression_)
2016-01-13 00:32:59 +00:00
{
children.push_back(input);
2019-05-16 17:16:25 +00:00
cached_header = children.back()->getHeader();
expression->execute(cached_header, true);
2016-01-13 00:32:59 +00:00
}
String ExpressionBlockInputStream::getName() const { return "Expression"; }
Block ExpressionBlockInputStream::getTotals()
2016-01-13 00:32:59 +00:00
{
totals = children.back()->getTotals();
expression->executeOnTotals(totals);
2016-01-13 00:32:59 +00:00
return totals;
2016-01-13 00:32:59 +00:00
}
Block ExpressionBlockInputStream::getHeader() const
{
return cached_header.cloneEmpty();
}
2016-01-13 00:32:59 +00:00
Block ExpressionBlockInputStream::readImpl()
{
2019-10-11 17:27:54 +00:00
if (!initialized)
{
if (expression->resultIsAlwaysEmpty())
return {};
initialized = true;
}
Block res = children.back()->read();
if (res)
expression->execute(res);
return res;
2016-01-13 00:32:59 +00:00
}
2020-01-20 14:17:55 +00:00
Block InflatingExpressionBlockInputStream::readImpl()
{
if (!initialized)
{
if (expression->resultIsAlwaysEmpty())
return {};
initialized = true;
}
Block res;
if (likely(!not_processed))
{
res = children.back()->read();
2020-01-15 20:33:29 +00:00
if (res)
expression->execute(res, not_processed, action_number);
}
else
2020-01-15 20:33:29 +00:00
{
res = std::move(not_processed->block);
expression->execute(res, not_processed, action_number);
}
return res;
}
2016-01-13 00:32:59 +00:00
}