1 | #include <Processors/Transforms/ExpressionTransform.h> |
2 | #include <Interpreters/ExpressionAnalyzer.h> |
3 | |
4 | namespace DB |
5 | { |
6 | |
7 | static Block (Block , const ExpressionActionsPtr & expression) |
8 | { |
9 | expression->execute(header, true); |
10 | return header; |
11 | } |
12 | |
13 | |
14 | ExpressionTransform::ExpressionTransform(const Block & , ExpressionActionsPtr expression_, bool on_totals_, bool default_totals_) |
15 | : ISimpleTransform(header_, transformHeader(header_, expression_), on_totals_) |
16 | , expression(std::move(expression_)) |
17 | , on_totals(on_totals_) |
18 | , default_totals(default_totals_) |
19 | { |
20 | } |
21 | |
22 | void ExpressionTransform::transform(Chunk & chunk) |
23 | { |
24 | if (!initialized) |
25 | { |
26 | initialized = true; |
27 | |
28 | if (expression->resultIsAlwaysEmpty()) |
29 | { |
30 | stopReading(); |
31 | chunk = Chunk(getOutputPort().getHeader().getColumns(), 0); |
32 | return; |
33 | } |
34 | } |
35 | |
36 | auto block = getInputPort().getHeader().cloneWithColumns(chunk.detachColumns()); |
37 | |
38 | if (on_totals) |
39 | { |
40 | if (default_totals && !expression->hasTotalsInJoin()) |
41 | return; |
42 | |
43 | expression->executeOnTotals(block); |
44 | } |
45 | else |
46 | expression->execute(block); |
47 | |
48 | auto num_rows = block.rows(); |
49 | chunk.setColumns(block.getColumns(), num_rows); |
50 | } |
51 | |
52 | } |
53 | |