1 | #pragma once |
2 | #include <Processors/ISimpleTransform.h> |
3 | |
4 | namespace DB |
5 | { |
6 | |
7 | /// Adds a materialized const column to the chunk with a specified value. |
8 | template <typename T> |
9 | class AddingConstColumnTransform : public ISimpleTransform |
10 | { |
11 | public: |
12 | AddingConstColumnTransform(const Block & , DataTypePtr data_type_, T value_, const String & column_name_) |
13 | : ISimpleTransform(header, addColumn(header, data_type_, column_name_), false) |
14 | , data_type(std::move(data_type_)), value(value_) {} |
15 | |
16 | String getName() const override { return "AddingConstColumnTransform" ; } |
17 | |
18 | protected: |
19 | void transform(Chunk & chunk) override |
20 | { |
21 | auto num_rows = chunk.getNumRows(); |
22 | chunk.addColumn(data_type->createColumnConst(num_rows, value)->convertToFullColumnIfConst()); |
23 | } |
24 | |
25 | private: |
26 | static Block addColumn(Block , const DataTypePtr & data_type, const String & column_name) |
27 | { |
28 | header.insert({data_type->createColumn(), data_type, column_name}); |
29 | return header; |
30 | } |
31 | |
32 | DataTypePtr data_type; |
33 | T value; |
34 | }; |
35 | |
36 | } |
37 | |