2013-06-01 07:43:57 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-01-23 14:48:50 +00:00
|
|
|
#include <DataStreams/IBlockInputStream.h>
|
2017-04-01 09:19:00 +00:00
|
|
|
#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
|
|
|
*/
|
2019-01-23 14:48:50 +00:00
|
|
|
class DistinctBlockInputStream : public IBlockInputStream
|
2013-06-01 07:43:57 +00:00
|
|
|
{
|
|
|
|
public:
|
2017-04-01 07:20:54 +00:00
|
|
|
/// 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
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
String getName() const override { return "Distinct"; }
|
2013-06-01 07:43:57 +00:00
|
|
|
|
2018-02-18 03:23:48 +00:00
|
|
|
Block getHeader() const override { return children.at(0)->getHeader(); }
|
2018-01-06 18:10:44 +00:00
|
|
|
|
2013-06-01 07:43:57 +00:00
|
|
|
protected:
|
2017-04-01 07:20:54 +00:00
|
|
|
Block readImpl() override;
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2016-11-10 21:24:40 +00:00
|
|
|
private:
|
2017-12-13 01:27:53 +00:00
|
|
|
ColumnRawPtrs getKeyColumns(const Block & block) const;
|
2016-12-22 17:00:23 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
template <typename Method>
|
|
|
|
void buildFilter(
|
|
|
|
Method & method,
|
2017-12-13 01:27:53 +00:00
|
|
|
const ColumnRawPtrs & key_columns,
|
2017-04-01 07:20:54 +00:00
|
|
|
IColumn::Filter & filter,
|
|
|
|
size_t rows,
|
|
|
|
SetVariants & variants) const;
|
2016-12-22 08:51:34 +00:00
|
|
|
|
2014-03-28 15:57:06 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
Names columns_names;
|
|
|
|
SetVariants data;
|
|
|
|
Sizes key_sizes;
|
2019-02-10 15:17:45 +00:00
|
|
|
UInt64 limit_hint;
|
2014-11-08 23:52:18 +00:00
|
|
|
|
2017-12-24 07:59:26 +00:00
|
|
|
bool no_more_rows = false;
|
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
/// Restrictions on the maximum size of the output data.
|
2018-03-11 00:15:26 +00:00
|
|
|
SizeLimits set_size_limits;
|
2013-06-01 07:43:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|