Coverage Report

Created: 2026-04-01 03:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/predicate/predicate_creator.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/predicate_creator.h"
19
20
#include "common/exception.h"
21
#include "exprs/create_predicate_function.h"
22
#include "storage/predicate/bitmap_filter_predicate.h"
23
#include "storage/predicate/bloom_filter_predicate.h"
24
25
namespace doris {
26
27
std::shared_ptr<ColumnPredicate> create_bloom_filter_predicate(
28
        const uint32_t cid, const std::string col_name, const DataTypePtr& data_type,
29
0
        const std::shared_ptr<BloomFilterFuncBase>& filter) {
30
    // Do the necessary type conversion, for CAST(STRING AS CHAR), we do nothing here but change the data type to the target type CHAR
31
0
    std::shared_ptr<BloomFilterFuncBase> filter_olap;
32
0
    filter_olap.reset(create_bloom_filter(data_type->get_primitive_type(), false));
33
0
    filter_olap->light_copy(filter.get());
34
0
    switch (data_type->get_primitive_type()) {
35
0
    case TYPE_TINYINT: {
36
0
        return BloomFilterColumnPredicate<TYPE_TINYINT>::create_shared(cid, col_name, filter_olap);
37
0
    }
38
0
    case TYPE_SMALLINT: {
39
0
        return BloomFilterColumnPredicate<TYPE_SMALLINT>::create_shared(cid, col_name, filter_olap);
40
0
    }
41
0
    case TYPE_INT: {
42
0
        return BloomFilterColumnPredicate<TYPE_INT>::create_shared(cid, col_name, filter_olap);
43
0
    }
44
0
    case TYPE_BIGINT: {
45
0
        return BloomFilterColumnPredicate<TYPE_BIGINT>::create_shared(cid, col_name, filter_olap);
46
0
    }
47
0
    case TYPE_LARGEINT: {
48
0
        return BloomFilterColumnPredicate<TYPE_LARGEINT>::create_shared(cid, col_name, filter_olap);
49
0
    }
50
0
    case TYPE_FLOAT: {
51
0
        return BloomFilterColumnPredicate<TYPE_FLOAT>::create_shared(cid, col_name, filter_olap);
52
0
    }
53
0
    case TYPE_DOUBLE: {
54
0
        return BloomFilterColumnPredicate<TYPE_DOUBLE>::create_shared(cid, col_name, filter_olap);
55
0
    }
56
0
    case TYPE_DECIMALV2: {
57
0
        return BloomFilterColumnPredicate<TYPE_DECIMALV2>::create_shared(cid, col_name,
58
0
                                                                         filter_olap);
59
0
    }
60
0
    case TYPE_DECIMAL32: {
61
0
        return BloomFilterColumnPredicate<TYPE_DECIMAL32>::create_shared(cid, col_name,
62
0
                                                                         filter_olap);
63
0
    }
64
0
    case TYPE_DECIMAL64: {
65
0
        return BloomFilterColumnPredicate<TYPE_DECIMAL64>::create_shared(cid, col_name,
66
0
                                                                         filter_olap);
67
0
    }
68
0
    case TYPE_DECIMAL128I: {
69
0
        return BloomFilterColumnPredicate<TYPE_DECIMAL128I>::create_shared(cid, col_name,
70
0
                                                                           filter_olap);
71
0
    }
72
0
    case TYPE_DECIMAL256: {
73
0
        return BloomFilterColumnPredicate<TYPE_DECIMAL256>::create_shared(cid, col_name,
74
0
                                                                          filter_olap);
75
0
    }
76
0
    case TYPE_CHAR: {
77
0
        return BloomFilterColumnPredicate<TYPE_CHAR>::create_shared(cid, col_name, filter_olap);
78
0
    }
79
0
    case TYPE_VARCHAR: {
80
0
        return BloomFilterColumnPredicate<TYPE_VARCHAR>::create_shared(cid, col_name, filter_olap);
81
0
    }
82
0
    case TYPE_STRING: {
83
0
        return BloomFilterColumnPredicate<TYPE_STRING>::create_shared(cid, col_name, filter_olap);
84
0
    }
85
0
    case TYPE_DATE: {
86
0
        return BloomFilterColumnPredicate<TYPE_DATE>::create_shared(cid, col_name, filter_olap);
87
0
    }
88
0
    case TYPE_DATEV2: {
89
0
        return BloomFilterColumnPredicate<TYPE_DATEV2>::create_shared(cid, col_name, filter_olap);
90
0
    }
91
0
    case TYPE_DATETIME: {
92
0
        return BloomFilterColumnPredicate<TYPE_DATETIME>::create_shared(cid, col_name, filter_olap);
93
0
    }
94
0
    case TYPE_DATETIMEV2: {
95
0
        return BloomFilterColumnPredicate<TYPE_DATETIMEV2>::create_shared(cid, col_name,
96
0
                                                                          filter_olap);
97
0
    }
98
0
    case TYPE_TIMESTAMPTZ: {
99
0
        return BloomFilterColumnPredicate<TYPE_TIMESTAMPTZ>::create_shared(cid, col_name,
100
0
                                                                           filter_olap);
101
0
    }
102
0
    case TYPE_BOOLEAN: {
103
0
        return BloomFilterColumnPredicate<TYPE_BOOLEAN>::create_shared(cid, col_name, filter_olap);
104
0
    }
105
0
    case TYPE_IPV4: {
106
0
        return BloomFilterColumnPredicate<TYPE_IPV4>::create_shared(cid, col_name, filter_olap);
107
0
    }
108
0
    case TYPE_IPV6: {
109
0
        return BloomFilterColumnPredicate<TYPE_IPV6>::create_shared(cid, col_name, filter_olap);
110
0
    }
111
0
    default:
112
0
        throw Exception(ErrorCode::INVALID_ARGUMENT,
113
0
                        fmt::format("Cannot use bloom filter for type: {}",
114
0
                                    type_to_string(data_type->get_primitive_type())));
115
0
        return nullptr;
116
0
    }
117
0
}
118
119
std::shared_ptr<ColumnPredicate> create_bitmap_filter_predicate(
120
        const uint32_t cid, const std::string col_name, const DataTypePtr& data_type,
121
0
        const std::shared_ptr<BitmapFilterFuncBase>& filter) {
122
0
    switch (data_type->get_primitive_type()) {
123
0
    case TYPE_TINYINT: {
124
0
        return BitmapFilterColumnPredicate<TYPE_TINYINT>::create_shared(cid, col_name, filter);
125
0
    }
126
0
    case TYPE_SMALLINT: {
127
0
        return BitmapFilterColumnPredicate<TYPE_SMALLINT>::create_shared(cid, col_name, filter);
128
0
    }
129
0
    case TYPE_INT: {
130
0
        return BitmapFilterColumnPredicate<TYPE_INT>::create_shared(cid, col_name, filter);
131
0
    }
132
0
    case TYPE_BIGINT: {
133
0
        return BitmapFilterColumnPredicate<TYPE_BIGINT>::create_shared(cid, col_name, filter);
134
0
    }
135
0
    default:
136
0
        throw Exception(ErrorCode::INVALID_ARGUMENT,
137
0
                        fmt::format("Cannot use bitmap filter for type: {}",
138
0
                                    type_to_string(data_type->get_primitive_type())));
139
0
        return nullptr;
140
0
    }
141
0
}
142
143
} // namespace doris