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_)
|
2012-07-24 18:21:39 +00:00
|
|
|
|
: input(input_), description(description_), has_been_read(false), log(&Logger::get("MergeSortingBlockInputStream"))
|
2011-09-04 21:23:19 +00:00
|
|
|
|
{
|
|
|
|
|
children.push_back(input);
|
|
|
|
|
}
|
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
|
|
|
|
|
2011-10-24 12:10:59 +00:00
|
|
|
|
BlockInputStreamPtr clone() { return new MergeSortingBlockInputStream(input, description); }
|
|
|
|
|
|
2012-10-20 02:10:47 +00:00
|
|
|
|
protected:
|
|
|
|
|
Block readImpl();
|
|
|
|
|
|
2011-09-04 01:42:14 +00:00
|
|
|
|
private:
|
|
|
|
|
BlockInputStreamPtr input;
|
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|