ClickHouse/dbms/src/DataStreams/DistinctBlockInputStream.h

53 lines
1.3 KiB
C++
Raw Normal View History

2013-06-01 07:43:57 +00:00
#pragma once
#include <DataStreams/IBlockInputStream.h>
#include <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 IBlockInputStream
2013-06-01 07:43:57 +00:00
{
public:
/// Empty columns_ means all collumns.
2019-02-10 15:17:45 +00:00
DistinctBlockInputStream(const BlockInputStreamPtr & input, const SizeLimits & set_size_limits, UInt64 limit_hint_, const Names & columns);
2013-06-01 07:43:57 +00:00
String getName() const override { return "Distinct"; }
2013-06-01 07:43:57 +00:00
Block getHeader() const override { return children.at(0)->getHeader(); }
2013-06-01 07:43:57 +00:00
protected:
Block readImpl() override;
private:
ColumnRawPtrs getKeyColumns(const Block & block) const;
2016-12-22 17:00:23 +00:00
template <typename Method>
void buildFilter(
Method & method,
const ColumnRawPtrs & key_columns,
IColumn::Filter & filter,
size_t rows,
SetVariants & variants) const;
Names columns_names;
SetVariants data;
Sizes key_sizes;
2019-02-10 15:17:45 +00:00
UInt64 limit_hint;
bool no_more_rows = false;
/// Restrictions on the maximum size of the output data.
SizeLimits set_size_limits;
2013-06-01 07:43:57 +00:00
};
}