1 | #pragma once |
---|---|
2 | |
3 | #include <DataStreams/IBlockOutputStream.h> |
4 | #include <DataStreams/SquashingTransform.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | /** Merging consecutive blocks of stream to specified minimum size. |
11 | */ |
12 | class SquashingBlockOutputStream : public IBlockOutputStream |
13 | { |
14 | public: |
15 | SquashingBlockOutputStream(BlockOutputStreamPtr dst, Block header_, size_t min_block_size_rows, size_t min_block_size_bytes); |
16 | |
17 | Block getHeader() const override { return header; } |
18 | void write(const Block & block) override; |
19 | |
20 | void flush() override; |
21 | void writePrefix() override; |
22 | void writeSuffix() override; |
23 | |
24 | /// Don't write blocks less than specified size even when flush method was called by user. |
25 | void disableFlush() { disable_flush = true; } |
26 | |
27 | private: |
28 | BlockOutputStreamPtr output; |
29 | Block header; |
30 | |
31 | SquashingTransform transform; |
32 | bool all_written = false; |
33 | |
34 | void finalize(); |
35 | |
36 | bool disable_flush = false; |
37 | }; |
38 | |
39 | } |
40 |