1 | #pragma once |
---|---|
2 | |
3 | #include <DataStreams/IBlockInputStream.h> |
4 | #include <Interpreters/SetVariants.h> |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | /** This class is intended for implementation of SELECT DISTINCT clause and |
10 | * leaves only unique rows in the stream. |
11 | * |
12 | * To optimize the SELECT DISTINCT ... LIMIT clause we can |
13 | * set limit_hint to non zero value. So we stop emitting new rows after |
14 | * count of already emitted rows will reach the limit_hint. |
15 | */ |
16 | class DistinctBlockInputStream : public IBlockInputStream |
17 | { |
18 | public: |
19 | /// Empty columns_ means all collumns. |
20 | DistinctBlockInputStream(const BlockInputStreamPtr & input, const SizeLimits & set_size_limits_, UInt64 limit_hint_, const Names & columns_); |
21 | |
22 | String getName() const override { return "Distinct"; } |
23 | |
24 | Block getHeader() const override { return children.at(0)->getHeader(); } |
25 | |
26 | protected: |
27 | Block readImpl() override; |
28 | |
29 | private: |
30 | ColumnRawPtrs getKeyColumns(const Block & block) const; |
31 | |
32 | template <typename Method> |
33 | void buildFilter( |
34 | Method & method, |
35 | const ColumnRawPtrs & key_columns, |
36 | IColumn::Filter & filter, |
37 | size_t rows, |
38 | SetVariants & variants) const; |
39 | |
40 | |
41 | Names columns_names; |
42 | SetVariants data; |
43 | Sizes key_sizes; |
44 | UInt64 limit_hint; |
45 | |
46 | bool no_more_rows = false; |
47 | |
48 | /// Restrictions on the maximum size of the output data. |
49 | SizeLimits set_size_limits; |
50 | }; |
51 | |
52 | } |
53 |