2013-06-01 07:43:57 +00:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <DB/DataStreams/IProfilingBlockInputStream.h>
|
2014-04-28 01:48:24 +00:00
|
|
|
|
#include <DB/Common/HashTable/HashSet.h>
|
2013-06-01 07:43:57 +00:00
|
|
|
|
#include <DB/Interpreters/AggregationCommon.h>
|
2013-06-20 12:12:27 +00:00
|
|
|
|
#include <DB/Interpreters/Limits.h>
|
2013-06-01 07:43:57 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/** Из потока блоков оставляет только уникальные строки.
|
|
|
|
|
* Для реализации SELECT DISTINCT ... .
|
|
|
|
|
* Если указан ненулевой limit - прекращает выдавать строки после того, как накопилось limit строк
|
|
|
|
|
* - для оптимизации SELECT DISTINCT ... LIMIT ... .
|
|
|
|
|
*/
|
|
|
|
|
class DistinctBlockInputStream : public IProfilingBlockInputStream
|
|
|
|
|
{
|
|
|
|
|
public:
|
2014-03-28 15:57:06 +00:00
|
|
|
|
/// Пустой columns_ значит все столбцы.
|
2015-01-21 04:17:02 +00:00
|
|
|
|
DistinctBlockInputStream(BlockInputStreamPtr input_, const Limits & limits, size_t limit_, Names columns_);
|
2013-06-01 07:43:57 +00:00
|
|
|
|
|
2015-06-08 20:22:02 +00:00
|
|
|
|
String getName() const override { return "Distinct"; }
|
2013-06-01 07:43:57 +00:00
|
|
|
|
|
2014-11-08 23:52:18 +00:00
|
|
|
|
String getID() const override
|
2013-06-01 07:43:57 +00:00
|
|
|
|
{
|
|
|
|
|
std::stringstream res;
|
|
|
|
|
res << "Distinct(" << children.back()->getID() << ")";
|
|
|
|
|
return res.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2015-01-21 04:17:02 +00:00
|
|
|
|
Block readImpl() override;
|
2013-06-01 07:43:57 +00:00
|
|
|
|
private:
|
2014-11-08 23:52:18 +00:00
|
|
|
|
|
2013-06-20 12:12:27 +00:00
|
|
|
|
bool checkLimits() const
|
|
|
|
|
{
|
|
|
|
|
if (max_rows && set.size() > max_rows)
|
|
|
|
|
return false;
|
|
|
|
|
if (max_bytes && set.getBufferSizeInBytes() > max_bytes)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2014-11-08 23:52:18 +00:00
|
|
|
|
|
2014-03-28 15:57:06 +00:00
|
|
|
|
Names columns_names;
|
|
|
|
|
|
2013-06-01 07:43:57 +00:00
|
|
|
|
size_t limit;
|
2014-11-08 23:52:18 +00:00
|
|
|
|
|
2013-06-20 12:12:27 +00:00
|
|
|
|
/// Ограничения на максимальный размер множества
|
|
|
|
|
size_t max_rows;
|
|
|
|
|
size_t max_bytes;
|
2014-02-17 23:56:45 +00:00
|
|
|
|
OverflowMode overflow_mode;
|
2013-06-01 07:43:57 +00:00
|
|
|
|
|
2015-02-20 19:48:52 +00:00
|
|
|
|
typedef HashSet<UInt128, UInt128TrivialHash> SetHashed;
|
2013-06-01 07:43:57 +00:00
|
|
|
|
SetHashed set;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|