ClickHouse/dbms/include/DB/DataStreams/DistinctBlockInputStream.h

56 lines
1.3 KiB
C++
Raw Normal View History

2013-06-01 07:43:57 +00:00
#pragma once
#include <DB/DataStreams/IProfilingBlockInputStream.h>
#include <DB/Interpreters/Limits.h>
#include <DB/Interpreters/SetVariants.h>
2013-06-01 07:43:57 +00:00
namespace DB
{
2016-12-23 08:01:35 +00:00
/** This class is intended for implementation of SELECT DISTINCT clause and
* leaves only unique rows in the stream.
*
* To optimize the SELECT DISTINCT ... LIMIT clause we can
* set limit_hint to non zero value. So we stop emitting new rows after
* count of already emitted rows will reach the limit_hint.
2013-06-01 07:43:57 +00:00
*/
class DistinctBlockInputStream : public IProfilingBlockInputStream
{
public:
2016-12-23 08:01:35 +00:00
/// Empty columns_ means all collumns.
DistinctBlockInputStream(BlockInputStreamPtr input_, const Limits & limits, size_t limit_hint_, Names columns_);
2013-06-01 07:43:57 +00:00
String getName() const override { return "Distinct"; }
2013-06-01 07:43:57 +00:00
String getID() const override;
2013-06-01 07:43:57 +00:00
protected:
Block readImpl() override;
private:
bool checkLimits() const;
2016-12-22 17:00:23 +00:00
ConstColumnPlainPtrs getKeyColumns(const Block & block) const;
template <typename Method>
2016-12-22 17:00:23 +00:00
void buildFilter(
Method & method,
const ConstColumnPlainPtrs & key_columns,
IColumn::Filter & filter,
size_t rows,
SetVariants & variants) const;
Names columns_names;
SetVariants data;
Sizes key_sizes;
size_t limit_hint;
2016-12-23 08:01:35 +00:00
/// Restrictions on the maximum size of the output data.
size_t max_rows;
size_t max_bytes;
OverflowMode overflow_mode;
2013-06-01 07:43:57 +00:00
};
}