2011-09-04 01:42:14 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2012-09-05 19:51:09 +00:00
|
|
|
|
#include <Yandex/logger_useful.h>
|
|
|
|
|
|
2011-09-04 01:42:14 +00:00
|
|
|
|
#include <DB/Core/SortDescription.h>
|
|
|
|
|
|
2011-09-04 21:23:19 +00:00
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
2011-09-04 01:42:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Соединяет поток сортированных по отдельности блоков в сортированный целиком поток.
|
|
|
|
|
*/
|
2011-09-04 21:23:19 +00:00
|
|
|
|
class MergeSortingBlockInputStream : public IProfilingBlockInputStream
|
2011-09-04 01:42:14 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MergeSortingBlockInputStream(BlockInputStreamPtr input_, SortDescription & description_)
|
2013-05-04 04:05:15 +00:00
|
|
|
|
: description(description_), has_been_read(false), log(&Logger::get("MergeSortingBlockInputStream"))
|
2011-09-04 21:23:19 +00:00
|
|
|
|
{
|
2013-05-04 04:05:15 +00:00
|
|
|
|
children.push_back(input_);
|
2011-09-04 21:23:19 +00:00
|
|
|
|
}
|
2011-09-04 01:42:14 +00:00
|
|
|
|
|
2011-09-04 21:23:19 +00:00
|
|
|
|
String getName() const { return "MergeSortingBlockInputStream"; }
|
2011-09-04 01:42:14 +00:00
|
|
|
|
|
2013-05-03 10:20:53 +00:00
|
|
|
|
String getID() const
|
|
|
|
|
{
|
|
|
|
|
std::stringstream res;
|
2013-05-04 05:20:07 +00:00
|
|
|
|
res << "MergeSorting(" << children.back()->getID();
|
2013-05-03 10:20:53 +00:00
|
|
|
|
|
|
|
|
|
for (size_t i = 0; i < description.size(); ++i)
|
|
|
|
|
res << ", " << description[i].getID();
|
|
|
|
|
|
|
|
|
|
res << ")";
|
|
|
|
|
return res.str();
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
|
protected:
|
|
|
|
|
Block readImpl();
|
|
|
|
|
|
2011-09-04 01:42:14 +00:00
|
|
|
|
private:
|
|
|
|
|
SortDescription description;
|
|
|
|
|
|
2012-07-23 20:01:29 +00:00
|
|
|
|
/// Всё было прочитано.
|
2012-03-05 02:34:20 +00:00
|
|
|
|
bool has_been_read;
|
|
|
|
|
|
2012-07-24 18:21:39 +00:00
|
|
|
|
Logger * log;
|
|
|
|
|
|
2012-07-27 20:25:48 +00:00
|
|
|
|
/** Слить сразу много блоков с помощью priority queue.
|
2012-07-25 20:33:43 +00:00
|
|
|
|
*/
|
2012-07-23 06:23:29 +00:00
|
|
|
|
Block merge(Blocks & blocks);
|
2011-09-04 01:42:14 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|