2012-06-25 02:52:51 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
using Poco::SharedPtr;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Объединяет несколько источников в один.
|
|
|
|
|
* В отличие от UnionBlockInputStream, делает это последовательно.
|
|
|
|
|
* Блоки разных источников не перемежаются друг с другом.
|
|
|
|
|
*/
|
|
|
|
|
class ConcatBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
ConcatBlockInputStream(BlockInputStreams inputs_)
|
|
|
|
|
{
|
|
|
|
|
children.insert(children.end(), inputs_.begin(), inputs_.end());
|
|
|
|
|
current_stream = children.begin();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-08 20:22:02 +00:00
|
|
|
|
String getName() const override { return "Concat"; }
|
2012-10-20 02:10:47 +00:00
|
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
|
String getID() const override
|
2013-05-03 10:20:53 +00:00
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
/// Будем считать, что порядок конкатенации блоков не имеет значения.
|
|
|
|
|
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:
|
2014-11-08 23:52:18 +00:00
|
|
|
|
Block readImpl() override
|
2012-06-25 02:52:51 +00:00
|
|
|
|
{
|
|
|
|
|
Block res;
|
|
|
|
|
|
|
|
|
|
while (current_stream != children.end())
|
|
|
|
|
{
|
|
|
|
|
res = (*current_stream)->read();
|
|
|
|
|
|
|
|
|
|
if (res)
|
|
|
|
|
break;
|
|
|
|
|
else
|
2015-04-18 22:33:24 +00:00
|
|
|
|
{
|
|
|
|
|
(*current_stream)->readSuffix();
|
2012-06-25 02:52:51 +00:00
|
|
|
|
++current_stream;
|
2015-04-18 22:33:24 +00:00
|
|
|
|
}
|
2012-06-25 02:52:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
BlockInputStreams::iterator current_stream;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|