1#include <Processors/ISimpleTransform.h>
2#include <Core/ColumnNumbers.h>
3
4namespace DB
5{
6
7/** Convert one block structure to another:
8 *
9 * Leaves only necessary columns;
10 *
11 * Columns are searched in source first by name;
12 * and if there is no column with same name, then by position.
13 *
14 * Converting types of matching columns (with CAST function).
15 *
16 * Materializing columns which are const in source and non-const in result,
17 * throw if they are const in result and non const in source,
18 * or if they are const and have different values.
19 */
20class ConvertingTransform : public ISimpleTransform
21{
22public:
23 enum class MatchColumnsMode
24 {
25 /// Require same number of columns in source and result. Match columns by corresponding positions, regardless to names.
26 Position,
27 /// Find columns in source by their names. Allow excessive columns in source.
28 Name,
29 };
30
31 ConvertingTransform(
32 Block source_header_,
33 Block result_header_,
34 MatchColumnsMode mode_,
35 const Context & context_);
36
37 String getName() const override { return "Converting"; }
38
39protected:
40 void transform(Chunk & chunk) override;
41
42private:
43 const Context & context;
44
45 /// How to construct result block. Position in source block, where to get each column.
46 ColumnNumbers conversion;
47};
48
49}
50