Coverage Report

Created: 2026-03-15 17:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/predicate/like_column_predicate.cpp
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
#include "storage/predicate/like_column_predicate.h"
19
20
#include "core/column/predicate_column.h"
21
#include "core/data_type/define_primitive_type.h"
22
#include "core/string_ref.h"
23
#include "exprs/function/like.h"
24
#include "exprs/function_context.h"
25
26
namespace doris {
27
28
template <PrimitiveType T>
29
LikeColumnPredicate<T>::LikeColumnPredicate(bool opposite, uint32_t column_id, std::string col_name,
30
                                            doris::FunctionContext* fn_ctx, doris::StringRef val)
31
0
        : ColumnPredicate(column_id, col_name, T, opposite), pattern(val) {
32
0
    static_assert(T == TYPE_VARCHAR || T == TYPE_CHAR || T == TYPE_STRING,
33
0
                  "LikeColumnPredicate only supports the following types: TYPE_VARCHAR, TYPE_CHAR, "
34
0
                  "TYPE_STRING");
35
0
    _state = reinterpret_cast<StateType*>(
36
0
            fn_ctx->get_function_state(doris::FunctionContext::THREAD_LOCAL));
37
0
    THROW_IF_ERROR(_state->search_state.clone(_like_state));
38
0
}
Unexecuted instantiation: _ZN5doris19LikeColumnPredicateILNS_13PrimitiveTypeE15EEC2EbjNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_15FunctionContextENS_9StringRefE
Unexecuted instantiation: _ZN5doris19LikeColumnPredicateILNS_13PrimitiveTypeE23EEC2EbjNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEPNS_15FunctionContextENS_9StringRefE
39
40
template <PrimitiveType T>
41
0
void LikeColumnPredicate<T>::evaluate_vec(const IColumn& column, uint16_t size, bool* flags) const {
42
0
    _evaluate_vec<false>(column, size, flags);
43
0
}
Unexecuted instantiation: _ZNK5doris19LikeColumnPredicateILNS_13PrimitiveTypeE15EE12evaluate_vecERKNS_7IColumnEtPb
Unexecuted instantiation: _ZNK5doris19LikeColumnPredicateILNS_13PrimitiveTypeE23EE12evaluate_vecERKNS_7IColumnEtPb
44
45
template <PrimitiveType T>
46
void LikeColumnPredicate<T>::evaluate_and_vec(const IColumn& column, uint16_t size,
47
0
                                              bool* flags) const {
48
0
    _evaluate_vec<true>(column, size, flags);
49
0
}
Unexecuted instantiation: _ZNK5doris19LikeColumnPredicateILNS_13PrimitiveTypeE15EE16evaluate_and_vecERKNS_7IColumnEtPb
Unexecuted instantiation: _ZNK5doris19LikeColumnPredicateILNS_13PrimitiveTypeE23EE16evaluate_and_vecERKNS_7IColumnEtPb
50
51
template <PrimitiveType T>
52
uint16_t LikeColumnPredicate<T>::_evaluate_inner(const IColumn& column, uint16_t* sel,
53
0
                                                 uint16_t size) const {
54
0
    uint16_t new_size = 0;
55
0
    if (column.is_nullable()) {
56
0
        auto* nullable_col = check_and_get_column<ColumnNullable>(column);
57
0
        auto& null_map_data = nullable_col->get_null_map_column().get_data();
58
0
        auto& nested_col = nullable_col->get_nested_column();
59
0
        if (nested_col.is_column_dictionary()) {
60
0
            auto* nested_col_ptr = check_and_get_column<ColumnDictI32>(nested_col);
61
0
            auto& data_array = nested_col_ptr->get_data();
62
0
            const auto& dict_res = _find_code_from_dictionary_column(*nested_col_ptr);
63
0
            if (!nullable_col->has_null()) {
64
0
                for (uint16_t i = 0; i != size; i++) {
65
0
                    uint16_t idx = sel[i];
66
0
                    sel[new_size] = idx;
67
0
                    unsigned char flag = dict_res[data_array[idx]];
68
0
                    new_size += _opposite ^ flag;
69
0
                }
70
0
            } else {
71
0
                for (uint16_t i = 0; i != size; i++) {
72
0
                    uint16_t idx = sel[i];
73
0
                    sel[new_size] = idx;
74
0
                    if (null_map_data[idx]) {
75
0
                        new_size += _opposite;
76
0
                        continue;
77
0
                    }
78
0
                    unsigned char flag = dict_res[data_array[idx]];
79
0
                    new_size += _opposite ^ flag;
80
0
                }
81
0
            }
82
0
        } else {
83
0
            auto* str_col = check_and_get_column<PredicateColumnType<T>>(nested_col);
84
0
            if (!nullable_col->has_null()) {
85
0
                ColumnUInt8::Container res(size, 0);
86
0
                for (uint16_t i = 0; i != size; i++) {
87
0
                    uint16_t idx = sel[i];
88
0
                    sel[new_size] = idx;
89
0
                    unsigned char flag = 0;
90
0
                    THROW_IF_ERROR((_state->scalar_function)(
91
0
                            &_like_state, str_col->get_data_at(idx), pattern, &flag));
92
0
                    new_size += _opposite ^ flag;
93
0
                }
94
0
            } else {
95
0
                for (uint16_t i = 0; i != size; i++) {
96
0
                    uint16_t idx = sel[i];
97
0
                    sel[new_size] = idx;
98
0
                    if (null_map_data[idx]) {
99
0
                        new_size += _opposite;
100
0
                        continue;
101
0
                    }
102
103
0
                    StringRef cell_value = str_col->get_data_at(idx);
104
0
                    unsigned char flag = 0;
105
0
                    THROW_IF_ERROR((_state->scalar_function)(
106
0
                            &_like_state, StringRef(cell_value.data, cell_value.size), pattern,
107
0
                            &flag));
108
0
                    new_size += _opposite ^ flag;
109
0
                }
110
0
            }
111
0
        }
112
0
    } else {
113
0
        if (column.is_column_dictionary()) {
114
0
            auto* nested_col_ptr = check_and_get_column<ColumnDictI32>(column);
115
0
            const auto& dict_res = _find_code_from_dictionary_column(*nested_col_ptr);
116
0
            auto& data_array = nested_col_ptr->get_data();
117
0
            for (uint16_t i = 0; i != size; i++) {
118
0
                uint16_t idx = sel[i];
119
0
                sel[new_size] = idx;
120
0
                unsigned char flag = dict_res[data_array[idx]];
121
0
                new_size += _opposite ^ flag;
122
0
            }
123
0
        } else {
124
0
            const PredicateColumnType<T>* str_col =
125
0
                    check_and_get_column<PredicateColumnType<T>>(column);
126
127
0
            ColumnUInt8::Container res(size, 0);
128
0
            for (uint16_t i = 0; i != size; i++) {
129
0
                uint16_t idx = sel[i];
130
0
                sel[new_size] = idx;
131
0
                unsigned char flag = 0;
132
0
                THROW_IF_ERROR((_state->scalar_function)(&_like_state, str_col->get_data_at(idx),
133
0
                                                         pattern, &flag));
134
0
                new_size += _opposite ^ flag;
135
0
            }
136
0
        }
137
0
    }
138
0
    return new_size;
139
0
}
Unexecuted instantiation: _ZNK5doris19LikeColumnPredicateILNS_13PrimitiveTypeE15EE15_evaluate_innerERKNS_7IColumnEPtt
Unexecuted instantiation: _ZNK5doris19LikeColumnPredicateILNS_13PrimitiveTypeE23EE15_evaluate_innerERKNS_7IColumnEPtt
140
141
template class LikeColumnPredicate<TYPE_CHAR>;
142
template class LikeColumnPredicate<TYPE_STRING>;
143
144
} //namespace doris