2021-07-22 16:05:52 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-05-20 19:49:31 +00:00
|
|
|
#include <Processors/ISource.h>
|
2021-07-22 16:05:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
/** A stream of blocks from which you can read the next block from an explicitly provided list.
|
2022-05-09 19:13:02 +00:00
|
|
|
* Also see SourceFromSingleChunk.
|
2021-07-22 16:05:52 +00:00
|
|
|
*/
|
2022-05-20 19:49:31 +00:00
|
|
|
class BlocksListSource : public ISource
|
2021-07-22 16:05:52 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// Acquires the ownership of the block list.
|
|
|
|
explicit BlocksListSource(BlocksList && list_)
|
2022-05-20 19:49:31 +00:00
|
|
|
: ISource(list_.empty() ? Block() : list_.front().cloneEmpty())
|
2021-07-22 16:05:52 +00:00
|
|
|
, 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_)
|
2022-05-20 19:49:31 +00:00
|
|
|
: ISource(begin_ == end_ ? Block() : begin_->cloneEmpty())
|
2021-07-22 16:05:52 +00:00
|
|
|
, 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|