2015-12-01 14:11:31 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2015-12-01 14:11:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
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.
|
2015-12-01 14:11:31 +00:00
|
|
|
*/
|
2019-01-23 14:48:50 +00:00
|
|
|
class BlocksListBlockInputStream : public IBlockInputStream
|
2015-12-01 14:11:31 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-05-13 22:19:04 +00:00
|
|
|
/// Acquires the ownership of the block list.
|
2017-04-01 07:20:54 +00:00
|
|
|
BlocksListBlockInputStream(BlocksList && list_)
|
|
|
|
: list(std::move(list_)), it(list.begin()), end(list.end()) {}
|
2015-12-01 14:11:31 +00:00
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/// Uses a list of blocks lying somewhere else.
|
2017-04-01 07:20:54 +00:00
|
|
|
BlocksListBlockInputStream(BlocksList::iterator & begin_, BlocksList::iterator & end_)
|
|
|
|
: it(begin_), end(end_) {}
|
2015-12-01 14:11:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "BlocksList"; }
|
2015-12-01 14:11:31 +00:00
|
|
|
|
|
|
|
protected:
|
2019-03-19 13:10:24 +00:00
|
|
|
Block getHeader() const override { return list.empty() ? Block() : *list.begin(); }
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override
|
|
|
|
{
|
|
|
|
if (it == end)
|
|
|
|
return Block();
|
2015-12-01 14:11:31 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Block res = *it;
|
|
|
|
++it;
|
|
|
|
return res;
|
|
|
|
}
|
2015-12-01 14:11:31 +00:00
|
|
|
|
|
|
|
private:
|
2017-04-01 07:20:54 +00:00
|
|
|
BlocksList list;
|
|
|
|
BlocksList::iterator it;
|
|
|
|
const BlocksList::iterator end;
|
2015-12-01 14:11:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|