1#pragma once
2
3#include <DataStreams/IBlockOutputStream.h>
4#include <Columns/ColumnConst.h>
5#include <Storages/ColumnDefault.h>
6#include <Interpreters/Context.h>
7
8
9namespace DB
10{
11
12
13/** This stream adds three types of columns into block
14 * 1. Columns, that are missed inside request, but present in table without defaults (missed columns)
15 * 2. Columns, that are missed inside request, but present in table with defaults (columns with default values)
16 * 3. Columns that materialized from other columns (materialized columns)
17 * All three types of columns are materialized (not constants).
18 */
19class AddingDefaultBlockOutputStream : public IBlockOutputStream
20{
21public:
22 AddingDefaultBlockOutputStream(
23 const BlockOutputStreamPtr & output_,
24 const Block & header_,
25 const Block & output_block_,
26 const ColumnDefaults & column_defaults_,
27 const Context & context_)
28 : output(output_), header(header_), output_block(output_block_),
29 column_defaults(column_defaults_), context(context_)
30 {
31 }
32
33 Block getHeader() const override { return header; }
34 void write(const Block & block) override;
35
36 void flush() override;
37
38 void writePrefix() override;
39 void writeSuffix() override;
40
41private:
42 BlockOutputStreamPtr output;
43 const Block header;
44 /// Blocks after this stream should have this structure
45 const Block output_block;
46 const ColumnDefaults column_defaults;
47 const Context & context;
48};
49
50
51}
52