ClickHouse/dbms/src/DataStreams/ConcatBlockInputStream.h

56 lines
1.2 KiB
C++
Raw Normal View History

2012-06-25 02:52:51 +00:00
#pragma once
#include <DataStreams/IBlockInputStream.h>
2012-06-25 02:52:51 +00:00
namespace DB
{
2017-05-13 22:19:04 +00:00
/** Combines several sources into one.
* Unlike UnionBlockInputStream, it does this sequentially.
* Blocks of different sources are not interleaved with each other.
2012-06-25 02:52:51 +00:00
*/
class ConcatBlockInputStream : public IBlockInputStream
2012-06-25 02:52:51 +00:00
{
public:
ConcatBlockInputStream(BlockInputStreams inputs_)
{
children.insert(children.end(), inputs_.begin(), inputs_.end());
current_stream = children.begin();
}
2012-06-25 02:52:51 +00:00
String getName() const override { return "Concat"; }
2012-10-20 02:10:47 +00:00
Block getHeader() const override { return children.at(0)->getHeader(); }
2019-02-08 15:21:06 +00:00
/// We call readSuffix prematurely by ourself. Suppress default behaviour.
void readSuffix() override {}
2012-10-20 02:10:47 +00:00
protected:
Block readImpl() override
{
Block res;
while (current_stream != children.end())
{
res = (*current_stream)->read();
if (res)
break;
else
{
(*current_stream)->readSuffix();
++current_stream;
}
}
return res;
}
2012-06-25 02:52:51 +00:00
private:
BlockInputStreams::iterator current_stream;
2012-06-25 02:52:51 +00:00
};
}