ClickHouse/dbms/src/DataStreams/BlocksListBlockInputStream.h

45 lines
1.0 KiB
C++
Raw Normal View History

#pragma once
#include <DataStreams/IBlockInputStream.h>
namespace DB
{
2017-05-13 22:19:04 +00:00
/** A stream of blocks from which you can read the next block from an explicitly provided list.
* Also see OneBlockInputStream.
*/
class BlocksListBlockInputStream : public IBlockInputStream
{
public:
2017-05-13 22:19:04 +00:00
/// Acquires the ownership of the block list.
BlocksListBlockInputStream(BlocksList && list_)
: list(std::move(list_)), it(list.begin()), end(list.end()) {}
2017-05-13 22:19:04 +00:00
/// Uses a list of blocks lying somewhere else.
BlocksListBlockInputStream(BlocksList::iterator & begin_, BlocksList::iterator & end_)
: it(begin_), end(end_) {}
String getName() const override { return "BlocksList"; }
protected:
2019-03-19 13:10:24 +00:00
Block getHeader() const override { return list.empty() ? Block() : *list.begin(); }
Block readImpl() override
{
if (it == end)
return Block();
Block res = *it;
++it;
return res;
}
private:
BlocksList list;
BlocksList::iterator it;
const BlocksList::iterator end;
};
}