Coverage Report

Created: 2026-03-15 22:41

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vbloom_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 "exprs/vbloom_predicate.h"
19
20
#include <cstddef>
21
#include <utility>
22
23
#include "common/status.h"
24
#include "core/block/block.h"
25
#include "core/block/column_numbers.h"
26
#include "core/block/column_with_type_and_name.h"
27
#include "core/column/column.h"
28
#include "core/column/column_nullable.h"
29
#include "core/column/column_vector.h"
30
#include "core/data_type/data_type.h"
31
#include "core/data_type/data_type_nullable.h"
32
#include "core/types.h"
33
#include "exprs/bloom_filter_func.h"
34
#include "runtime/runtime_state.h"
35
36
namespace doris {
37
class RowDescriptor;
38
class TExprNode;
39
40
} // namespace doris
41
42
namespace doris {
43
#include "common/compile_check_begin.h"
44
45
class VExprContext;
46
47
22.6k
VBloomPredicate::VBloomPredicate(const TExprNode& node) : VExpr(node), _filter(nullptr) {}
48
49
Status VBloomPredicate::prepare(RuntimeState* state, const RowDescriptor& desc,
50
22.6k
                                VExprContext* context) {
51
22.6k
    RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context));
52
53
22.6k
    if (_children.size() != 1) {
54
0
        return Status::InternalError("Invalid argument for VBloomPredicate.");
55
0
    }
56
57
22.6k
    _prepare_finished = true;
58
22.6k
    return Status::OK();
59
22.6k
}
60
61
Status VBloomPredicate::open(RuntimeState* state, VExprContext* context,
62
23.8k
                             FunctionContext::FunctionStateScope scope) {
63
23.8k
    DCHECK(_prepare_finished);
64
23.8k
    RETURN_IF_ERROR(VExpr::open(state, context, scope));
65
23.8k
    _open_finished = true;
66
23.8k
    return Status::OK();
67
23.8k
}
68
69
23.9k
void VBloomPredicate::close(VExprContext* context, FunctionContext::FunctionStateScope scope) {
70
23.9k
    VExpr::close(context, scope);
71
23.9k
}
72
73
Status VBloomPredicate::_do_execute(VExprContext* context, const Block* block,
74
                                    const uint8_t* __restrict filter, Selector* selector,
75
2.16k
                                    size_t count, ColumnPtr& result_column) const {
76
2.16k
    DCHECK(_open_finished || block == nullptr);
77
2.16k
    DCHECK(!(filter != nullptr && selector != nullptr))
78
0
            << "filter and selector can not be both set";
79
2.16k
    DCHECK_EQ(_children.size(), 1);
80
81
2.16k
    ColumnPtr argument_column;
82
2.16k
    RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, argument_column));
83
2.16k
    argument_column = argument_column->convert_to_full_column_if_const();
84
85
2.16k
    size_t sz = argument_column->size();
86
2.16k
    auto res_data_column = ColumnUInt8::create(sz);
87
88
2.16k
    res_data_column->resize(sz);
89
2.16k
    auto* ptr = ((ColumnUInt8*)res_data_column.get())->get_data().data();
90
91
2.16k
    _filter->find_fixed_len(argument_column, ptr, filter);
92
93
2.16k
    result_column = std::move(res_data_column);
94
2.16k
    DCHECK_EQ(result_column->size(), count);
95
2.16k
    return Status::OK();
96
2.16k
}
97
98
Status VBloomPredicate::execute_column(VExprContext* context, const Block* block,
99
                                       Selector* selector, size_t count,
100
476
                                       ColumnPtr& result_column) const {
101
476
    return _do_execute(context, block, nullptr, selector, count, result_column);
102
476
}
103
104
Status VBloomPredicate::execute_runtime_filter(VExprContext* context, const Block* block,
105
                                               const uint8_t* __restrict filter, size_t count,
106
                                               ColumnPtr& result_column,
107
1.69k
                                               ColumnPtr* arg_column) const {
108
1.69k
    return _do_execute(context, block, filter, nullptr, count, result_column);
109
1.69k
}
110
22.6k
const std::string& VBloomPredicate::expr_name() const {
111
22.6k
    return EXPR_NAME;
112
22.6k
}
113
114
22.6k
void VBloomPredicate::set_filter(std::shared_ptr<BloomFilterFuncBase> filter) {
115
22.6k
    _filter = filter;
116
22.6k
}
117
118
21.9k
uint64_t VBloomPredicate::get_digest(uint64_t seed) const {
119
21.9k
    seed = _children[0]->get_digest(seed);
120
21.9k
    if (seed) {
121
21.9k
        char* data;
122
21.9k
        int len;
123
21.9k
        _filter->get_data(&data, &len);
124
21.9k
        return HashUtil::hash64(data, len, seed);
125
21.9k
    }
126
18
    return 0;
127
21.9k
}
128
129
#include "common/compile_check_end.h"
130
} // namespace doris