aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Processors/Sources/BlocksListSource.h
blob: 5cdf08251ed6657cb52deac09ba646e135659319 (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
39
40
41
42
43
44
45
46
47
#pragma once

#include <Processors/ISource.h>


namespace DB
{

/** A stream of blocks from which you can read the next block from an explicitly provided list.
  * Also see SourceFromSingleChunk.
  */
class BlocksListSource : public ISource
{
public:
    /// Acquires the ownership of the block list.
    explicit BlocksListSource(BlocksList && list_)
        : ISource(list_.empty() ? Block() : list_.front().cloneEmpty())
        , list(std::move(list_)), it(list.begin()), end(list.end()) {}

    /// Uses a list of blocks lying somewhere else.
    BlocksListSource(BlocksList::iterator & begin_, BlocksList::iterator & end_)
        : ISource(begin_ == end_ ? Block() : begin_->cloneEmpty())
        , it(begin_), end(end_) {}

    String getName() const override { return "BlocksListSource"; }

protected:

    Chunk generate() override
    {
        if (it == end)
            return {};

        Block res = *it;
        ++it;

        size_t num_rows = res.rows();
        return Chunk(res.getColumns(), num_rows);
    }

private:
    BlocksList list;
    BlocksList::iterator it;
    const BlocksList::iterator end;
};

}