|
34 | 34 |
|
35 | 35 | #pragma once |
36 | 36 |
|
37 | | -#include <boost/container/flat_set.hpp> |
38 | | -#include <boost/lexical_cast.hpp> |
39 | 37 | #include <cstdint> |
40 | | -#include <map> |
| 38 | +#include <memory> |
41 | 39 | #include <sstream> |
42 | 40 | #include <string> |
43 | 41 | #include <utility> |
44 | | -#include <variant> |
| 42 | +#include <vector> |
45 | 43 |
|
46 | | -#include "base/string/slice.h" |
47 | | -#include "column/runtime_type_traits.h" |
48 | 44 | #include "exec/olap_utils.h" |
49 | | -#include "exec/scan_node.h" |
50 | | -#include "gen_cpp/PlanNodes_types.h" |
51 | | -#include "gutil/stl_util.h" |
52 | | -#include "gutil/strings/substitute.h" |
| 45 | +#include "storage/primitive/column_value_range.h" |
53 | 46 | #include "storage/primitive/olap_tuple.h" |
54 | | -#include "types/date_value.h" |
55 | | -#include "types/datetime_value.h" |
56 | | -#include "types/timestamp_value.h" |
57 | 47 |
|
58 | 48 | namespace starrocks { |
59 | 49 |
|
60 | | -// There are two types of value range: Fixed Value Range and Range Value Range |
61 | | -// I know "Range Value Range" sounds bad, but it's hard to turn over the de facto. |
62 | | -// Fixed Value Range means discrete values in the set, like "IN (1,2,3)" |
63 | | -// Range Value Range means range values like ">= 10 && <= 20" |
64 | | -/** |
65 | | - * @brief Column's value range |
66 | | - **/ |
67 | | -template <class T> |
68 | | -class ColumnValueRange { |
69 | | -public: |
70 | | - using RangeValueType = T; |
71 | | - using ValuesContainer = boost::container::flat_set<T>; |
72 | | - using iterator_type = typename ValuesContainer::iterator; |
73 | | - |
74 | | - ColumnValueRange(); |
75 | | - ColumnValueRange(std::string col_name, LogicalType type, T min, T max); |
76 | | - ColumnValueRange(std::string col_name, LogicalType type, T type_min, T type_max, T min, T max); |
77 | | - |
78 | | - Status add_fixed_values(SQLFilterOp op, const ValuesContainer& values); |
79 | | - |
80 | | - Status add_range(SQLFilterOp op, T value); |
81 | | - |
82 | | - void set_precision(int precision); |
83 | | - |
84 | | - void set_scale(int scale); |
85 | | - |
86 | | - int precision() const; |
87 | | - |
88 | | - int scale() const; |
89 | | - |
90 | | - bool is_fixed_value_range() const; |
91 | | - |
92 | | - bool is_empty_value_range() const; |
93 | | - |
94 | | - bool is_full_value_range() const; |
95 | | - |
96 | | - bool is_init_state() const { return _is_init_state; } |
97 | | - |
98 | | - bool is_fixed_value_convertible() const; |
99 | | - |
100 | | - SQLFilterOp fixed_value_operator() const { return _fixed_op; } |
101 | | - |
102 | | - bool is_range_value_convertible() const; |
103 | | - |
104 | | - size_t get_convertible_fixed_value_size() const; |
105 | | - |
106 | | - void convert_to_fixed_value(); |
107 | | - |
108 | | - void convert_to_range_value(); |
109 | | - |
110 | | - const ValuesContainer& get_fixed_value_set() const { return _fixed_values; } |
111 | | - |
112 | | - T get_range_max_value() const { return _high_value; } |
113 | | - |
114 | | - T get_range_min_value() const { return _low_value; } |
115 | | - |
116 | | - bool is_low_value_mininum() const { return _low_value == _type_min; } |
117 | | - |
118 | | - bool is_high_value_maximum() const { return _high_value == _type_max; } |
119 | | - |
120 | | - bool is_begin_include() const { return _low_op == FILTER_LARGER_OR_EQUAL; } |
121 | | - |
122 | | - bool is_end_include() const { return _high_op == FILTER_LESS_OR_EQUAL; } |
123 | | - |
124 | | - LogicalType type() const { return _column_type; } |
125 | | - |
126 | | - size_t get_fixed_value_size() const { return _fixed_values.size(); } |
127 | | - |
128 | | - void set_index_filter_only(bool is_index_only) { _is_index_filter_only = is_index_only; } |
129 | | - |
130 | | - template <typename ConditionType, bool Negative = false> |
131 | | - void to_olap_filter(std::vector<ConditionType>& filters); |
132 | | - |
133 | | - template <typename ConditionType> |
134 | | - ConditionType to_olap_not_null_filter() const; |
135 | | - |
136 | | - void clear(); |
137 | | - void clear_to_empty(); |
138 | | - |
139 | | -private: |
140 | | - std::string _column_name; |
141 | | - LogicalType _column_type{TYPE_UNKNOWN}; // Column type (eg: TINYINT,SMALLINT,INT,BIGINT) |
142 | | - int _precision; // casting a decimalv3-typed value into string need precision |
143 | | - int _scale; // casting a decimalv3-typed value into string need scale |
144 | | - T _type_min; // Column type's min value |
145 | | - T _type_max; // Column type's max value |
146 | | - T _low_value; // Column's low value, closed interval at left |
147 | | - T _high_value; // Column's high value, open interval at right |
148 | | - SQLFilterOp _low_op; |
149 | | - SQLFilterOp _high_op; |
150 | | - ValuesContainer _fixed_values; // Column's fixed values |
151 | | - SQLFilterOp _fixed_op; |
152 | | - // Whether this condition only used to filter index, not filter chunk row in storage engine |
153 | | - bool _is_index_filter_only = false; |
154 | | - // ColumnValueRange don't call add_range or add_fixed_values |
155 | | - bool _is_init_state = true; |
156 | | - |
157 | | - bool _empty_range = false; |
158 | | -}; |
159 | | - |
160 | 50 | class OlapScanKeys { |
161 | 51 | public: |
162 | 52 | OlapScanKeys() = default; |
@@ -206,20 +96,4 @@ class OlapScanKeys { |
206 | 96 | bool _is_convertible{true}; |
207 | 97 | }; |
208 | 98 |
|
209 | | -// clang-format off |
210 | | -using ColumnValueRangeType = std::variant< |
211 | | - ColumnValueRange<int8_t>, |
212 | | - ColumnValueRange<uint8_t>, // vectorized boolean |
213 | | - ColumnValueRange<int16_t>, |
214 | | - ColumnValueRange<int32_t>, |
215 | | - ColumnValueRange<int64_t>, |
216 | | - ColumnValueRange<__int128>, |
217 | | - ColumnValueRange<int256_t>, |
218 | | - ColumnValueRange<Slice>, |
219 | | - ColumnValueRange<DecimalV2Value>, |
220 | | - ColumnValueRange<bool>, |
221 | | - ColumnValueRange<DateValue>, |
222 | | - ColumnValueRange<TimestampValue>>; |
223 | | -// clang-format on |
224 | | - |
225 | 99 | } // namespace starrocks |
0 commit comments