Coverage Report

Created: 2026-01-09 23:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/exec/olap_utils.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <fmt/core.h>
21
#include <gen_cpp/Opcodes_types.h>
22
#include <glog/logging.h>
23
#include <math.h>
24
25
#include "common/logging.h"
26
#include "olap/olap_tuple.h"
27
#include "runtime/primitive_type.h"
28
29
namespace doris {
30
31
using CompareLargeFunc = bool (*)(const void*, const void*);
32
33
static const char* NEGATIVE_INFINITY = "-oo";
34
static const char* POSITIVE_INFINITY = "+oo";
35
36
struct OlapScanRange {
37
public:
38
0
    OlapScanRange() : begin_include(true), end_include(true) {
39
0
        begin_scan_range.add_value(NEGATIVE_INFINITY);
40
0
        end_scan_range.add_value(POSITIVE_INFINITY);
41
0
    }
42
    OlapScanRange(bool begin, bool end, std::vector<std::string>& begin_range,
43
                  std::vector<std::string>& end_range)
44
            : begin_include(begin),
45
              end_include(end),
46
              begin_scan_range(begin_range),
47
0
              end_scan_range(end_range) {}
48
49
    bool begin_include;
50
    bool end_include;
51
    OlapTuple begin_scan_range;
52
    OlapTuple end_scan_range;
53
54
0
    std::string debug_string() const {
55
0
        fmt::memory_buffer buf;
56
0
        DCHECK_EQ(begin_scan_range.size(), end_scan_range.size());
57
0
        for (int i = 0; i < begin_scan_range.size(); i++) {
58
0
            fmt::format_to(buf, "({}, {})\n", begin_scan_range[i], end_scan_range[i]);
59
0
        }
60
0
        return fmt::to_string(buf);
61
0
    }
62
};
63
64
enum SQLFilterOp {
65
    FILTER_LARGER = 0,
66
    FILTER_LARGER_OR_EQUAL = 1,
67
    FILTER_LESS = 2,
68
    FILTER_LESS_OR_EQUAL = 3,
69
    FILTER_IN = 4,
70
    FILTER_NOT_IN = 5,
71
    FILTER_EQ = 6,
72
    FILTER_NE = 7
73
};
74
75
template <PrimitiveType>
76
constexpr bool always_false_v = false;
77
78
207
inline SQLFilterOp to_olap_filter_type(const std::string& function_name) {
79
207
    if (function_name == "lt") {
80
26
        return FILTER_LESS;
81
181
    } else if (function_name == "gt") {
82
26
        return FILTER_LARGER;
83
155
    } else if (function_name == "le") {
84
28
        return FILTER_LESS_OR_EQUAL;
85
127
    } else if (function_name == "ge") {
86
28
        return FILTER_LARGER_OR_EQUAL;
87
99
    } else if (function_name == "eq") {
88
33
        return FILTER_EQ;
89
66
    } else if (function_name == "ne") {
90
28
        return FILTER_NE;
91
38
    } else if (function_name == "in") {
92
19
        return FILTER_IN;
93
19
    } else if (function_name == "not_in") {
94
19
        return FILTER_NOT_IN;
95
19
    } else {
96
0
        DCHECK(false) << "Function Name: " << function_name;
97
0
        return FILTER_IN;
98
0
    }
99
207
}
100
101
enum class MatchType {
102
    UNKNOWN = -1,
103
    MATCH_ANY = 0,
104
    MATCH_ALL = 1,
105
    MATCH_PHRASE = 2,
106
    MATCH_PHRASE_PREFIX = 8,
107
    MATCH_REGEXP = 9,
108
    MATCH_PHRASE_EDGE = 10,
109
};
110
111
0
inline MatchType to_match_type(TExprOpcode::type type) {
112
0
    switch (type) {
113
0
    case TExprOpcode::type::MATCH_ANY:
114
0
        return MatchType::MATCH_ANY;
115
0
        break;
116
0
    case TExprOpcode::type::MATCH_ALL:
117
0
        return MatchType::MATCH_ALL;
118
0
        break;
119
0
    case TExprOpcode::type::MATCH_PHRASE:
120
0
        return MatchType::MATCH_PHRASE;
121
0
        break;
122
0
    case TExprOpcode::type::MATCH_PHRASE_PREFIX:
123
0
        return MatchType::MATCH_PHRASE_PREFIX;
124
0
        break;
125
0
    case TExprOpcode::type::MATCH_REGEXP:
126
0
        return MatchType::MATCH_REGEXP;
127
0
        break;
128
0
    case TExprOpcode::type::MATCH_PHRASE_EDGE:
129
0
        return MatchType::MATCH_PHRASE_EDGE;
130
0
        break;
131
0
    default:
132
0
        VLOG_CRITICAL << "TExprOpcode: " << type;
133
0
        DCHECK(false);
134
0
    }
135
0
    return MatchType::MATCH_ANY;
136
0
}
137
138
0
inline MatchType to_match_type(const std::string& condition_op) {
139
0
    if (condition_op.compare("match_any") == 0) {
140
0
        return MatchType::MATCH_ANY;
141
0
    } else if (condition_op.compare("match_all") == 0) {
142
0
        return MatchType::MATCH_ALL;
143
0
    } else if (condition_op.compare("match_phrase") == 0) {
144
0
        return MatchType::MATCH_PHRASE;
145
0
    } else if (condition_op.compare("match_phrase_prefix") == 0) {
146
0
        return MatchType::MATCH_PHRASE_PREFIX;
147
0
    } else if (condition_op.compare("match_regexp") == 0) {
148
0
        return MatchType::MATCH_REGEXP;
149
0
    } else if (condition_op.compare("match_phrase_edge") == 0) {
150
0
        return MatchType::MATCH_PHRASE_EDGE;
151
0
    }
152
0
    return MatchType::UNKNOWN;
153
0
}
154
155
0
inline bool is_match_condition(const std::string& op) {
156
0
    if (0 == strcasecmp(op.c_str(), "match_any") || 0 == strcasecmp(op.c_str(), "match_all") ||
157
0
        0 == strcasecmp(op.c_str(), "match_phrase") ||
158
0
        0 == strcasecmp(op.c_str(), "match_phrase_prefix") ||
159
0
        0 == strcasecmp(op.c_str(), "match_regexp") ||
160
0
        0 == strcasecmp(op.c_str(), "match_phrase_edge")) {
161
0
        return true;
162
0
    }
163
0
    return false;
164
0
}
165
166
0
inline bool is_match_operator(const TExprOpcode::type& op_type) {
167
0
    return TExprOpcode::MATCH_ANY == op_type || TExprOpcode::MATCH_ALL == op_type ||
168
0
           TExprOpcode::MATCH_PHRASE == op_type || TExprOpcode::MATCH_PHRASE_PREFIX == op_type ||
169
0
           TExprOpcode::MATCH_REGEXP == op_type || TExprOpcode::MATCH_PHRASE_EDGE == op_type;
170
0
}
171
172
} // namespace doris