1#pragma once
2
3#include <DataStreams/IBlockInputStream.h>
4
5
6namespace DB
7{
8
9/** A stream of blocks from which you can read one block.
10 * Also see BlocksListBlockInputStream.
11 */
12class OneBlockInputStream : public IBlockInputStream
13{
14public:
15 explicit OneBlockInputStream(Block block_) : block(std::move(block_)) { block.checkNumberOfRows(); }
16
17 String getName() const override { return "One"; }
18
19 Block getHeader() const override
20 {
21 Block res;
22 for (const auto & elem : block)
23 res.insert({ elem.column->cloneEmpty(), elem.type, elem.name });
24 return res;
25 }
26
27protected:
28 Block readImpl() override
29 {
30 if (has_been_read)
31 return Block();
32
33 has_been_read = true;
34 return block;
35 }
36
37private:
38 Block block;
39 bool has_been_read = false;
40};
41
42}
43