2017-04-01 09:19:00 +00:00
|
|
|
#include <Interpreters/ExpressionActions.h>
|
|
|
|
#include <DataStreams/ExpressionBlockInputStream.h>
|
2016-01-13 00:32:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-09-08 03:47:27 +00:00
|
|
|
ExpressionBlockInputStream::ExpressionBlockInputStream(const BlockInputStreamPtr & input, const ExpressionActionsPtr & expression_)
|
2017-04-01 07:20:54 +00:00
|
|
|
: expression(expression_)
|
2016-01-13 00:32:59 +00:00
|
|
|
{
|
2017-09-08 02:29:47 +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"; }
|
|
|
|
|
2018-02-23 10:43:24 +00:00
|
|
|
Block ExpressionBlockInputStream::getTotals()
|
2016-01-13 00:32:59 +00:00
|
|
|
{
|
2019-01-23 14:48:50 +00:00
|
|
|
totals = children.back()->getTotals();
|
|
|
|
expression->executeOnTotals(totals);
|
2016-01-13 00:32:59 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return totals;
|
2016-01-13 00:32:59 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 03:23:48 +00:00
|
|
|
Block ExpressionBlockInputStream::getHeader() const
|
2018-01-06 18:10:44 +00:00
|
|
|
{
|
2019-05-14 18:26:19 +00:00
|
|
|
return cached_header.cloneEmpty();
|
2018-01-06 18:10:44 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Block res = children.back()->read();
|
2019-06-17 16:27:18 +00:00
|
|
|
if (res)
|
|
|
|
expression->execute(res);
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
2016-01-13 00:32:59 +00:00
|
|
|
}
|
|
|
|
|
2020-01-20 14:17:55 +00:00
|
|
|
Block InflatingExpressionBlockInputStream::readImpl()
|
2020-01-13 18:00:32 +00:00
|
|
|
{
|
|
|
|
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);
|
2020-01-13 18:00:32 +00:00
|
|
|
}
|
|
|
|
else
|
2020-01-15 20:33:29 +00:00
|
|
|
{
|
|
|
|
res = std::move(not_processed->block);
|
|
|
|
expression->execute(res, not_processed, action_number);
|
|
|
|
}
|
2020-01-13 18:00:32 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2016-01-13 00:32:59 +00:00
|
|
|
}
|