1 | #pragma once |
2 | |
3 | #include <vector> |
4 | #include <memory> |
5 | #include <cstddef> |
6 | #include <string> |
7 | #include <Core/Field.h> |
8 | |
9 | class Collator; |
10 | |
11 | namespace DB |
12 | { |
13 | |
14 | struct FillColumnDescription |
15 | { |
16 | /// All missed values in range [FROM, TO) will be filled |
17 | /// Range [FROM, TO) respects sorting direction |
18 | Field fill_from; /// Fill value >= FILL_FROM |
19 | Field fill_to; /// Fill value + STEP < FILL_TO |
20 | Field fill_step; /// Default = 1 or -1 according to direction |
21 | }; |
22 | |
23 | /// Description of the sorting rule by one column. |
24 | struct SortColumnDescription |
25 | { |
26 | std::string column_name; /// The name of the column. |
27 | size_t column_number; /// Column number (used if no name is given). |
28 | int direction; /// 1 - ascending, -1 - descending. |
29 | int nulls_direction; /// 1 - NULLs and NaNs are greater, -1 - less. |
30 | /// To achieve NULLS LAST, set it equal to direction, to achieve NULLS FIRST, set it opposite. |
31 | std::shared_ptr<Collator> collator; /// Collator for locale-specific comparison of strings |
32 | bool with_fill; |
33 | FillColumnDescription fill_description; |
34 | |
35 | |
36 | SortColumnDescription( |
37 | size_t column_number_, int direction_, int nulls_direction_, |
38 | const std::shared_ptr<Collator> & collator_ = nullptr, bool with_fill_ = false, |
39 | const FillColumnDescription & fill_description_ = {}) |
40 | : column_number(column_number_), direction(direction_), nulls_direction(nulls_direction_), collator(collator_) |
41 | , with_fill(with_fill_), fill_description(fill_description_) {} |
42 | |
43 | SortColumnDescription( |
44 | const std::string & column_name_, int direction_, int nulls_direction_, |
45 | const std::shared_ptr<Collator> & collator_ = nullptr, bool with_fill_ = false, |
46 | const FillColumnDescription & fill_description_ = {}) |
47 | : column_name(column_name_), column_number(0), direction(direction_), nulls_direction(nulls_direction_) |
48 | , collator(collator_), with_fill(with_fill_), fill_description(fill_description_) {} |
49 | |
50 | bool operator == (const SortColumnDescription & other) const |
51 | { |
52 | return column_name == other.column_name && column_number == other.column_number |
53 | && direction == other.direction && nulls_direction == other.nulls_direction; |
54 | } |
55 | |
56 | bool operator != (const SortColumnDescription & other) const |
57 | { |
58 | return !(*this == other); |
59 | } |
60 | }; |
61 | |
62 | /// Description of the sorting rule for several columns. |
63 | using SortDescription = std::vector<SortColumnDescription>; |
64 | |
65 | } |
66 | |