2011-09-04 00:22:19 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
2011-09-04 01:42:14 +00:00
|
|
|
|
#include <DB/Core/SortDescription.h>
|
2011-09-04 00:22:19 +00:00
|
|
|
|
|
2011-09-04 21:23:19 +00:00
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
2011-09-04 00:22:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Сортирует каждый блок по отдельности по значениям указанных столбцов.
|
2011-09-04 01:42:14 +00:00
|
|
|
|
* На данный момент, используется не очень оптимальный алгоритм.
|
2011-09-04 00:22:19 +00:00
|
|
|
|
*/
|
2011-09-04 21:23:19 +00:00
|
|
|
|
class PartialSortingBlockInputStream : public IProfilingBlockInputStream
|
2011-09-04 00:22:19 +00:00
|
|
|
|
{
|
|
|
|
|
public:
|
2013-09-16 05:44:47 +00:00
|
|
|
|
/// limit - если не 0, то можно каждый блок сортировать не полностью, а только limit первых по порядку строк.
|
|
|
|
|
PartialSortingBlockInputStream(BlockInputStreamPtr input_, SortDescription & description_, size_t limit_ = 0)
|
|
|
|
|
: description(description_), limit(limit_)
|
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 00:22:19 +00:00
|
|
|
|
|
2011-09-04 21:23:19 +00:00
|
|
|
|
String getName() const { return "PartialSortingBlockInputStream"; }
|
2011-09-04 00:22:19 +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 << "PartialSorting(" << 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 00:22:19 +00:00
|
|
|
|
private:
|
2011-09-04 01:42:14 +00:00
|
|
|
|
SortDescription description;
|
2013-09-16 05:44:47 +00:00
|
|
|
|
size_t limit;
|
2011-09-04 00:22:19 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|