1 | #pragma once |
---|---|
2 | |
3 | #include <DataStreams/IBlockInputStream.h> |
4 | |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | |
10 | /** Combines several sources into one. |
11 | * Unlike UnionBlockInputStream, it does this sequentially. |
12 | * Blocks of different sources are not interleaved with each other. |
13 | */ |
14 | class ConcatBlockInputStream : public IBlockInputStream |
15 | { |
16 | public: |
17 | ConcatBlockInputStream(BlockInputStreams inputs_) |
18 | { |
19 | children.insert(children.end(), inputs_.begin(), inputs_.end()); |
20 | current_stream = children.begin(); |
21 | } |
22 | |
23 | String getName() const override { return "Concat"; } |
24 | |
25 | Block getHeader() const override { return children.at(0)->getHeader(); } |
26 | |
27 | /// We call readSuffix prematurely by ourself. Suppress default behaviour. |
28 | void readSuffix() override {} |
29 | |
30 | protected: |
31 | Block readImpl() override |
32 | { |
33 | Block res; |
34 | |
35 | while (current_stream != children.end()) |
36 | { |
37 | res = (*current_stream)->read(); |
38 | |
39 | if (res) |
40 | break; |
41 | else |
42 | { |
43 | (*current_stream)->readSuffix(); |
44 | ++current_stream; |
45 | } |
46 | } |
47 | |
48 | return res; |
49 | } |
50 | |
51 | private: |
52 | BlockInputStreams::iterator current_stream; |
53 | }; |
54 | |
55 | } |
56 |