blob: a0e35ebbee5b793b3e066d077b520d8072b94f6b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#pragma once
#include <Processors/ISource.h>
namespace DB
{
/// Source that generates chunks with constant columns and
/// size up to max_block_size with total rows total_num_rows.
class ConstChunkGenerator : public ISource
{
public:
ConstChunkGenerator(Block header, size_t total_num_rows, size_t max_block_size_)
: ISource(std::move(header))
, remaining_rows(total_num_rows), max_block_size(max_block_size_)
{
}
String getName() const override { return "ConstChunkGenerator"; }
protected:
Chunk generate() override
{
if (!remaining_rows)
return {};
size_t num_rows = std::min(max_block_size, remaining_rows);
remaining_rows -= num_rows;
return cloneConstWithDefault(Chunk{getPort().getHeader().getColumns(), 0}, num_rows);
}
private:
size_t remaining_rows;
size_t max_block_size;
};
}
|