Coverage Report

Created: 2026-03-12 17:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vbitmap_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/vbitmap_predicate.h"
19
20
#include <cstddef>
21
#include <utility>
22
23
#include "core/block/block.h"
24
#include "core/block/column_numbers.h"
25
#include "core/block/column_with_type_and_name.h"
26
#include "core/block/columns_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/string_ref.h"
32
#include "core/types.h"
33
#include "exprs/bitmapfilter_predicate.h"
34
35
namespace doris {
36
class RowDescriptor;
37
class RuntimeState;
38
class TExprNode;
39
40
} // namespace doris
41
42
namespace doris {
43
#include "common/compile_check_begin.h"
44
45
class VExprContext;
46
47
51
VBitmapPredicate::VBitmapPredicate(const TExprNode& node) : VExpr(node), _filter(nullptr) {}
48
49
doris::Status VBitmapPredicate::prepare(doris::RuntimeState* state, const RowDescriptor& desc,
50
50
                                        VExprContext* context) {
51
50
    RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context));
52
53
50
    if (_children.size() != 1) {
54
0
        return Status::InternalError("Invalid argument for VBitmapPredicate.");
55
0
    }
56
57
50
    ColumnsWithTypeAndName argument_template;
58
50
    argument_template.reserve(_children.size());
59
50
    for (auto child : _children) {
60
49
        auto column = child->data_type()->create_column();
61
49
        argument_template.emplace_back(std::move(column), child->data_type(), child->expr_name());
62
49
    }
63
50
    _prepare_finished = true;
64
50
    return Status::OK();
65
50
}
66
67
doris::Status VBitmapPredicate::open(doris::RuntimeState* state, VExprContext* context,
68
286
                                     FunctionContext::FunctionStateScope scope) {
69
286
    DCHECK(_prepare_finished);
70
286
    RETURN_IF_ERROR(VExpr::open(state, context, scope));
71
286
    _open_finished = true;
72
286
    return Status::OK();
73
286
}
74
75
Status VBitmapPredicate::_do_execute(VExprContext* context, const Block* block,
76
                                     const uint8_t* __restrict filter, Selector* selector,
77
116
                                     size_t count, ColumnPtr& result_column) const {
78
116
    DCHECK(_open_finished || block == nullptr);
79
116
    DCHECK(!(filter != nullptr && selector != nullptr))
80
0
            << "filter and selector can not be both set";
81
116
    DCHECK_EQ(_children.size(), 1);
82
83
116
    ColumnPtr argument_column;
84
116
    RETURN_IF_ERROR(_children[0]->execute_column(context, block, selector, count, argument_column));
85
116
    argument_column = argument_column->convert_to_full_column_if_const();
86
87
116
    size_t sz = argument_column->size();
88
116
    auto res_data_column = ColumnUInt8::create(sz);
89
116
    res_data_column->resize(sz);
90
116
    auto* ptr = res_data_column->get_data().data();
91
92
116
    if (argument_column->is_nullable()) {
93
116
        auto column_nested =
94
116
                assert_cast<const ColumnNullable*>(argument_column.get())->get_nested_column_ptr();
95
116
        auto column_nullmap = assert_cast<const ColumnNullable*>(argument_column.get())
96
116
                                      ->get_null_map_column_ptr();
97
116
        _filter->find_batch(column_nested->get_raw_data().data,
98
116
                            (uint8_t*)column_nullmap->get_raw_data().data, sz, ptr, filter);
99
116
    } else {
100
0
        _filter->find_batch(argument_column->get_raw_data().data, nullptr, sz, ptr, filter);
101
0
    }
102
103
116
    result_column = std::move(res_data_column);
104
116
    DCHECK_EQ(result_column->size(), count);
105
116
    return Status::OK();
106
116
}
107
108
Status VBitmapPredicate::execute_column(VExprContext* context, const Block* block,
109
                                        Selector* selector, size_t count,
110
0
                                        ColumnPtr& result_column) const {
111
0
    return _do_execute(context, block, nullptr, selector, count, result_column);
112
0
}
113
114
Status VBitmapPredicate::execute_runtime_filter(VExprContext* context, const Block* block,
115
                                                const uint8_t* __restrict filter, size_t count,
116
                                                ColumnPtr& result_column,
117
116
                                                ColumnPtr* arg_column) const {
118
116
    return _do_execute(context, block, filter, nullptr, count, result_column);
119
116
}
120
121
291
void VBitmapPredicate::close(VExprContext* context, FunctionContext::FunctionStateScope scope) {
122
291
    VExpr::close(context, scope);
123
291
}
124
125
49
const std::string& VBitmapPredicate::expr_name() const {
126
49
    return EXPR_NAME;
127
49
}
128
129
51
void VBitmapPredicate::set_filter(std::shared_ptr<BitmapFilterFuncBase> filter) {
130
51
    _filter = filter;
131
51
}
132
133
#include "common/compile_check_end.h"
134
} // namespace doris