Skip to content

Commit f2ebe2d

Browse files
[Refactor] Move scan range filter primitives to storage primitive
Signed-off-by: alvin-phoenix-ai <alvin.zhao@phoenixdata.ai>
1 parent 95b660b commit f2ebe2d

32 files changed

Lines changed: 1091 additions & 913 deletions

be/src/exec/olap_common.cpp

Lines changed: 4 additions & 602 deletions
Large diffs are not rendered by default.

be/src/exec/olap_common.h

Lines changed: 3 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -34,129 +34,19 @@
3434

3535
#pragma once
3636

37-
#include <boost/container/flat_set.hpp>
38-
#include <boost/lexical_cast.hpp>
3937
#include <cstdint>
40-
#include <map>
38+
#include <memory>
4139
#include <sstream>
4240
#include <string>
4341
#include <utility>
44-
#include <variant>
42+
#include <vector>
4543

46-
#include "base/string/slice.h"
47-
#include "column/runtime_type_traits.h"
4844
#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"
5346
#include "storage/primitive/olap_tuple.h"
54-
#include "types/date_value.h"
55-
#include "types/datetime_value.h"
56-
#include "types/timestamp_value.h"
5747

5848
namespace starrocks {
5949

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-
16050
class OlapScanKeys {
16151
public:
16252
OlapScanKeys() = default;
@@ -206,20 +96,4 @@ class OlapScanKeys {
20696
bool _is_convertible{true};
20797
};
20898

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-
22599
} // namespace starrocks

be/src/exec/olap_scan_prepare.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "exec/olap_common.h"
2020
#include "exprs/expr.h"
2121
#include "exprs/expr_context.h"
22-
#include "filter_condition.h"
2322
#include "runtime/descriptors.h"
23+
#include "storage/primitive/filter_condition.h"
2424
#include "storage/primitive/predicate_tree/predicate_tree_fwd.h"
2525
#include "storage/primitive/predicate_tree_params.h"
2626
#include "storage/runtime_filter_predicate.h"

be/src/exec/olap_utils.h

Lines changed: 1 addition & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,8 @@
3636

3737
#include <cmath>
3838

39-
#include "column/runtime_type_traits.h"
40-
#include "common/logging.h"
41-
#include "gen_cpp/Exprs_types.h"
42-
#include "gen_cpp/Opcodes_types.h"
39+
#include "storage/primitive/filter_op.h"
4340
#include "storage/primitive/olap_tuple.h"
44-
#include "types/datetime_value.h"
45-
#include "types/logical_type.h"
46-
#include "types/logical_type_infra.h"
4741

4842
namespace starrocks {
4943

@@ -66,75 +60,4 @@ typedef struct OlapScanRange {
6660
OlapTuple end_scan_range;
6761
} OlapScanRange;
6862

69-
enum SQLFilterOp {
70-
FILTER_LARGER = 0,
71-
FILTER_LARGER_OR_EQUAL = 1,
72-
FILTER_LESS = 2,
73-
FILTER_LESS_OR_EQUAL = 3,
74-
FILTER_IN = 4,
75-
FILTER_NOT_IN = 5
76-
};
77-
78-
inline SQLFilterOp to_olap_filter_type(TExprOpcode::type type, bool opposite) {
79-
switch (type) {
80-
case TExprOpcode::LT:
81-
return opposite ? FILTER_LARGER : FILTER_LESS;
82-
case TExprOpcode::LE:
83-
//TODO: Datetime may be truncated to a date column, so we convert LT to LE,
84-
// for example: '2010-01-01 00:00:01' will be truncate to '2010-01-01'
85-
return opposite ? FILTER_LARGER_OR_EQUAL : FILTER_LESS_OR_EQUAL;
86-
case TExprOpcode::GT:
87-
return opposite ? FILTER_LESS : FILTER_LARGER;
88-
89-
case TExprOpcode::GE:
90-
return opposite ? FILTER_LESS_OR_EQUAL : FILTER_LARGER_OR_EQUAL;
91-
92-
case TExprOpcode::EQ:
93-
return opposite ? FILTER_NOT_IN : FILTER_IN;
94-
95-
case TExprOpcode::NE:
96-
return opposite ? FILTER_IN : FILTER_NOT_IN;
97-
98-
case TExprOpcode::EQ_FOR_NULL:
99-
return FILTER_IN;
100-
101-
default:
102-
VLOG(2) << "TExprOpcode: " << type;
103-
DCHECK(false);
104-
}
105-
106-
return FILTER_IN;
107-
}
108-
109-
inline SQLFilterOp invert_olap_filter_type(const SQLFilterOp op) {
110-
switch (op) {
111-
case FILTER_LARGER:
112-
return FILTER_LESS_OR_EQUAL;
113-
case FILTER_LARGER_OR_EQUAL:
114-
return FILTER_LESS;
115-
case FILTER_LESS:
116-
return FILTER_LARGER_OR_EQUAL;
117-
case FILTER_LESS_OR_EQUAL:
118-
return FILTER_LARGER;
119-
case FILTER_IN:
120-
return FILTER_NOT_IN;
121-
case FILTER_NOT_IN:
122-
return FILTER_IN;
123-
default:
124-
VLOG(2) << "Unkown SQLFilterOp when inverting it: " << op;
125-
DCHECK(false);
126-
}
127-
return FILTER_IN;
128-
}
129-
130-
template <bool Negative>
131-
SQLFilterOp to_olap_filter_type(TExprOpcode::type type, bool opposite) {
132-
const auto op = to_olap_filter_type(type, opposite);
133-
if constexpr (Negative) {
134-
return invert_olap_filter_type(op);
135-
} else {
136-
return op;
137-
}
138-
}
139-
14063
} // namespace starrocks

be/src/exec/pipeline/set/except_context.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
#include "exec/pipeline/set/except_context.h"
1616

17+
#include "exprs/expr.h"
1718
#include "runtime/current_thread.h"
19+
#include "runtime/descriptors.h"
1820
#include "runtime/exec_env.h"
1921
#include "runtime/runtime_state.h"
2022

be/src/exec/pipeline/set/except_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
#include "column/runtime_type_traits.h"
2424
#include "common/statusor.h"
2525
#include "exec/except_hash_set.h"
26-
#include "exec/olap_common.h"
2726
#include "exec/pipeline/context_with_dependency.h"
2827
#include "exec/pipeline/primitives/pipeline_observer.h"
2928
#include "exprs/expr_context.h"
3029
#include "gutil/casts.h"
30+
#include "runtime/descriptors_fwd.h"
3131
#include "runtime/mem_pool.h"
3232

3333
namespace starrocks::pipeline {

be/src/exec/pipeline/set/intersect_context.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414

1515
#include "exec/pipeline/set/intersect_context.h"
1616

17+
#include "exprs/expr.h"
1718
#include "runtime/current_thread.h"
19+
#include "runtime/descriptors.h"
1820
#include "runtime/runtime_state.h"
1921

2022
namespace starrocks::pipeline {

be/src/exec/pipeline/set/intersect_context.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
#include "column/runtime_type_traits.h"
2424
#include "common/statusor.h"
2525
#include "exec/intersect_hash_set.h"
26-
#include "exec/olap_common.h"
2726
#include "exec/pipeline/context_with_dependency.h"
2827
#include "exec/pipeline/primitives/pipeline_observer.h"
2928
#include "exprs/expr_context.h"
3029
#include "gutil/casts.h"
30+
#include "runtime/descriptors_fwd.h"
3131
#include "runtime/mem_pool.h"
3232

3333
namespace starrocks::pipeline {

be/src/formats/parquet/column_reader.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
#include "formats/parquet/scalar_column_reader.h"
3030
#include "formats/utils.h"
3131
#include "gen_cpp/parquet_types.h"
32-
#include "storage/column_or_predicate.h"
3332
#include "storage/column_predicate_factory.h"
33+
#include "storage/primitive/column_or_predicate.h"
3434

3535
namespace starrocks::parquet {
3636

be/src/formats/parquet/file_reader.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "gen_cpp/parquet_types.h"
3737
#include "gutil/casts.h"
3838
#include "gutil/strings/substitute.h"
39+
#include "storage/runtime_range_pruner.hpp"
3940

4041
namespace starrocks::parquet {
4142

0 commit comments

Comments
 (0)