ClickHouse/dbms/src/DataStreams/ConcatBlockInputStream.h

70 lines
1.6 KiB
C++
Raw Normal View History

2012-06-25 02:52:51 +00:00
#pragma once
#include <DataStreams/IProfilingBlockInputStream.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 IProfilingBlockInputStream
{
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
String getID() const override
{
std::stringstream res;
res << "Concat(";
Strings children_ids(children.size());
for (size_t i = 0; i < children.size(); ++i)
children_ids[i] = children[i]->getID();
2017-05-13 22:19:04 +00:00
/// Let's assume that the order of concatenation of blocks does not matter.
std::sort(children_ids.begin(), children_ids.end());
for (size_t i = 0; i < children_ids.size(); ++i)
res << (i == 0 ? "" : ", ") << children_ids[i];
res << ")";
return res.str();
}
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
};
}