2012-06-25 02:52:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-04-01 09:19:00 +00:00
|
|
|
#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:
|
2017-04-01 07:20:54 +00:00
|
|
|
ConcatBlockInputStream(BlockInputStreams inputs_)
|
|
|
|
{
|
|
|
|
children.insert(children.end(), inputs_.begin(), inputs_.end());
|
|
|
|
current_stream = children.begin();
|
|
|
|
}
|
2012-06-25 02:52:51 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "Concat"; }
|
2012-10-20 02:10:47 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getID() const override
|
|
|
|
{
|
|
|
|
std::stringstream res;
|
|
|
|
res << "Concat(";
|
2013-05-03 10:20:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Strings children_ids(children.size());
|
|
|
|
for (size_t i = 0; i < children.size(); ++i)
|
|
|
|
children_ids[i] = children[i]->getID();
|
2013-05-03 10:20:53 +00:00
|
|
|
|
2017-05-13 22:19:04 +00:00
|
|
|
/// Let's assume that the order of concatenation of blocks does not matter.
|
2017-04-01 07:20:54 +00:00
|
|
|
std::sort(children_ids.begin(), children_ids.end());
|
2013-05-03 10:20:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
for (size_t i = 0; i < children_ids.size(); ++i)
|
|
|
|
res << (i == 0 ? "" : ", ") << children_ids[i];
|
2013-05-03 10:20:53 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
res << ")";
|
|
|
|
return res.str();
|
|
|
|
}
|
2013-05-03 10:20:53 +00:00
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
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:
|
2017-04-01 07:20:54 +00:00
|
|
|
BlockInputStreams::iterator current_stream;
|
2012-06-25 02:52:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|