Coverage Report

Created: 2026-04-17 14:13

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
44
class VExprContext;
45
46
9.48k
VBloomPredicate::VBloomPredicate(const TExprNode& node) : VExpr(node), _filter(nullptr) {}
47
48
Status VBloomPredicate::prepare(RuntimeState* state, const RowDescriptor& desc,
49
9.46k
                                VExprContext* context) {
50
9.46k
    RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context));
51
52
9.46k
    if (_children.size() != 1) {
53
0
        return Status::InternalError("Invalid argument for VBloomPredicate.");
54
0
    }
55
56
9.46k
    _prepare_finished = true;
57
9.46k
    return Status::OK();
58
9.46k
}
59
60
Status VBloomPredicate::open(RuntimeState* state, VExprContext* context,
61
11.1k
                             FunctionContext::FunctionStateScope scope) {
62
11.1k
    DCHECK(_prepare_finished);
63
11.1k
    RETURN_IF_ERROR(VExpr::open(state, context, scope));
64
11.1k
    _open_finished = true;
65
11.1k
    return Status::OK();
66
11.1k
}
67
68
11.2k
void VBloomPredicate::close(VExprContext* context, FunctionContext::FunctionStateScope scope) {
69
11.2k
    VExpr::close(context, scope);
70
11.2k
}
71
72
Status VBloomPredicate::_do_execute(VExprContext* context, const Block* block,
73
                                    const uint8_t* __restrict filter, Selector* selector,
74
1.87k
                                    size_t count, ColumnPtr& result_column) const {
75
1.87k
    DCHECK(_open_finished || block == nullptr);
76
1.87k
    DCHECK(!(filter != nullptr && selector != nullptr))
77
0
            << "filter and selector can not be both set";
78
1.87k
    DCHECK_EQ(_children.size(), 1);
79
80
1.87k
    ColumnPtr argument_column;
81
1.87k
    RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, argument_column));
82
1.87k
    argument_column = argument_column->convert_to_full_column_if_const();
83
84
1.87k
    size_t sz = argument_column->size();
85
1.87k
    auto res_data_column = ColumnUInt8::create(sz);
86
87
1.87k
    res_data_column->resize(sz);
88
1.87k
    auto* ptr = ((ColumnUInt8*)res_data_column.get())->get_data().data();
89
90
1.87k
    _filter->find_fixed_len(argument_column, ptr, filter);
91
92
1.87k
    result_column = std::move(res_data_column);
93
1.87k
    DCHECK_EQ(result_column->size(), count);
94
1.87k
    return Status::OK();
95
1.87k
}
96
97
Status VBloomPredicate::execute_column(VExprContext* context, const Block* block,
98
                                       Selector* selector, size_t count,
99
223
                                       ColumnPtr& result_column) const {
100
223
    return _do_execute(context, block, nullptr, selector, count, result_column);
101
223
}
102
103
Status VBloomPredicate::execute_runtime_filter(VExprContext* context, const Block* block,
104
                                               const uint8_t* __restrict filter, size_t count,
105
                                               ColumnPtr& result_column,
106
1.64k
                                               ColumnPtr* arg_column) const {
107
1.64k
    return _do_execute(context, block, filter, nullptr, count, result_column);
108
1.64k
}
109
9.44k
const std::string& VBloomPredicate::expr_name() const {
110
9.44k
    return EXPR_NAME;
111
9.44k
}
112
113
9.48k
void VBloomPredicate::set_filter(std::shared_ptr<BloomFilterFuncBase> filter) {
114
9.48k
    _filter = filter;
115
9.48k
}
116
117
9.05k
uint64_t VBloomPredicate::get_digest(uint64_t seed) const {
118
9.05k
    seed = _children[0]->get_digest(seed);
119
9.05k
    if (seed) {
120
9.05k
        char* data;
121
9.05k
        int len;
122
9.05k
        _filter->get_data(&data, &len);
123
9.05k
        return HashUtil::hash64(data, len, seed);
124
9.05k
    }
125
3
    return 0;
126
9.05k
}
127
128
} // namespace doris