1 | #pragma once |
---|---|
2 | |
3 | #include <DataStreams/IBlockInputStream.h> |
4 | #include <DataStreams/copyData.h> |
5 | |
6 | |
7 | namespace DB |
8 | { |
9 | |
10 | class IBlockOutputStream; |
11 | using BlockOutputStreamPtr = std::shared_ptr<IBlockOutputStream>; |
12 | |
13 | |
14 | /** An empty stream of blocks. |
15 | * But at the first read attempt, copies the data from the passed `input` to the `output`. |
16 | * This is necessary to execute the query INSERT SELECT - the query copies data, but returns nothing. |
17 | * The query could be executed without wrapping it in an empty BlockInputStream, |
18 | * but the progress of query execution and the ability to cancel the query would not work. |
19 | */ |
20 | class NullAndDoCopyBlockInputStream : public IBlockInputStream |
21 | { |
22 | public: |
23 | NullAndDoCopyBlockInputStream(const BlockInputStreamPtr & input_, BlockOutputStreamPtr output_) |
24 | : input(input_), output(output_) |
25 | { |
26 | children.push_back(input_); |
27 | } |
28 | |
29 | /// Suppress readPrefix and readSuffix, because they are called by copyData. |
30 | void readPrefix() override {} |
31 | void readSuffix() override {} |
32 | |
33 | String getName() const override { return "NullAndDoCopy"; } |
34 | |
35 | Block getHeader() const override { return {}; } |
36 | Block getTotals() override { return {}; } |
37 | Block getExtremes() override { return {}; } |
38 | |
39 | protected: |
40 | Block readImpl() override |
41 | { |
42 | copyData(*input, *output); |
43 | return Block(); |
44 | } |
45 | |
46 | private: |
47 | BlockInputStreamPtr input; |
48 | BlockOutputStreamPtr output; |
49 | }; |
50 | |
51 | } |
52 |