Coverage Report

Created: 2026-03-16 16:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/table_function/vexplode_bitmap.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/table_function/vexplode_bitmap.h"
19
20
#include <glog/logging.h>
21
22
#include <memory>
23
#include <ostream>
24
25
#include "common/status.h"
26
#include "core/block/block.h"
27
#include "core/block/column_with_type_and_name.h"
28
#include "core/column/column.h"
29
#include "core/column/column_nullable.h"
30
#include "core/string_ref.h"
31
#include "core/value/bitmap_value.h"
32
#include "exprs/table_function/table_function.h"
33
#include "exprs/vexpr.h"
34
#include "exprs/vexpr_context.h"
35
36
namespace doris {
37
#include "common/compile_check_begin.h"
38
39
210
VExplodeBitmapTableFunction::VExplodeBitmapTableFunction() {
40
210
    _fn_name = "vexplode_bitmap";
41
210
}
42
43
68
Status VExplodeBitmapTableFunction::process_init(Block* block, RuntimeState* state) {
44
68
    CHECK(_expr_context->root()->children().size() == 1)
45
0
            << "VExplodeNumbersTableFunction must be have 1 children but have "
46
0
            << _expr_context->root()->children().size();
47
48
68
    RETURN_IF_ERROR(_expr_context->root()->children()[0]->execute_column(
49
68
            _expr_context.get(), block, nullptr, block->rows(), _value_column));
50
51
68
    return Status::OK();
52
68
}
53
54
200
void VExplodeBitmapTableFunction::reset() {
55
200
    _eos = false;
56
200
    _cur_offset = 0;
57
200
    if (!current_empty()) {
58
16
        _cur_iter = std::make_unique<BitmapValueIterator>(*_cur_bitmap);
59
16
    }
60
200
}
61
62
24
void VExplodeBitmapTableFunction::forward(int step) {
63
24
    if (!current_empty()) {
64
48
        for (int i = 0; i < step; i++) {
65
24
            ++(*_cur_iter);
66
24
        }
67
24
    }
68
24
    TableFunction::forward(step);
69
24
}
70
71
24
void VExplodeBitmapTableFunction::get_same_many_values(MutableColumnPtr& column, int length) {
72
24
    if (current_empty()) {
73
0
        column->insert_many_defaults(length);
74
24
    } else {
75
24
        if (_is_nullable) {
76
12
            assert_cast<ColumnInt64*>(
77
12
                    assert_cast<ColumnNullable*>(column.get())->get_nested_column_ptr().get())
78
12
                    ->insert_many_vals(**_cur_iter, length);
79
12
            assert_cast<ColumnUInt8*>(
80
12
                    assert_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
81
12
                    ->insert_many_defaults(length);
82
12
        } else {
83
12
            assert_cast<ColumnInt64*>(column.get())->insert_many_vals(**_cur_iter, length);
84
12
        }
85
24
    }
86
24
}
87
88
184
void VExplodeBitmapTableFunction::process_row(size_t row_idx) {
89
184
    TableFunction::process_row(row_idx);
90
    //FIXME: use ColumnComplex instead
91
184
    StringRef value = _value_column->get_data_at(row_idx);
92
93
184
    if (value.data) {
94
182
        _cur_bitmap = reinterpret_cast<const BitmapValue*>(value.data);
95
96
182
        _cur_size = _cur_bitmap->cardinality();
97
182
        if (!current_empty()) {
98
160
            _cur_iter = std::make_unique<BitmapValueIterator>(*_cur_bitmap);
99
160
        }
100
182
    }
101
184
}
102
103
68
void VExplodeBitmapTableFunction::process_close() {
104
68
    _value_column = nullptr;
105
68
}
106
107
182
int VExplodeBitmapTableFunction::get_value(MutableColumnPtr& column, int max_step) {
108
182
    max_step = std::min(max_step, (int)(_cur_size - _cur_offset));
109
    // should dispose the empty status, forward one step
110
182
    if (current_empty()) {
111
2
        column->insert_default();
112
2
        max_step = 1;
113
180
    } else {
114
180
        ColumnInt64* target = nullptr;
115
180
        if (_is_nullable) {
116
72
            target = assert_cast<ColumnInt64*>(
117
72
                    assert_cast<ColumnNullable*>(column.get())->get_nested_column_ptr().get());
118
72
            assert_cast<ColumnUInt8*>(
119
72
                    assert_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
120
72
                    ->insert_many_defaults(max_step);
121
108
        } else {
122
108
            target = assert_cast<ColumnInt64*>(column.get());
123
108
        }
124
180
        auto origin_size = target->size();
125
180
        target->resize(origin_size + max_step);
126
180
        auto* target_data = target->get_data().data();
127
100k
        for (int i = 0; i < max_step; ++i) {
128
100k
            target_data[i + origin_size] = **_cur_iter;
129
100k
            ++(*_cur_iter);
130
100k
        }
131
180
    }
132
182
    TableFunction::forward(max_step);
133
182
    return max_step;
134
182
}
135
#include "common/compile_check_end.h"
136
} // namespace doris