1#include <Interpreters/ExpressionActions.h>
2#include <DataStreams/ExpressionBlockInputStream.h>
3
4
5namespace DB
6{
7
8ExpressionBlockInputStream::ExpressionBlockInputStream(const BlockInputStreamPtr & input, const ExpressionActionsPtr & expression_)
9 : expression(expression_)
10{
11 children.push_back(input);
12 cached_header = children.back()->getHeader();
13 expression->execute(cached_header, true);
14}
15
16String ExpressionBlockInputStream::getName() const { return "Expression"; }
17
18Block ExpressionBlockInputStream::getTotals()
19{
20 totals = children.back()->getTotals();
21 expression->executeOnTotals(totals);
22
23 return totals;
24}
25
26Block ExpressionBlockInputStream::getHeader() const
27{
28 return cached_header.cloneEmpty();
29}
30
31Block ExpressionBlockInputStream::readImpl()
32{
33 if (!initialized)
34 {
35 if (expression->resultIsAlwaysEmpty())
36 return {};
37
38 initialized = true;
39 }
40
41 Block res = children.back()->read();
42 if (res)
43 expression->execute(res);
44 return res;
45}
46
47}
48