Coverage Report

Created: 2026-04-10 18:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/table_function/vexplode_numbers.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_numbers.h"
19
20
#include <glog/logging.h>
21
22
#include <ostream>
23
24
#include "common/status.h"
25
#include "core/assert_cast.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_const.h"
30
#include "core/column/column_nullable.h"
31
#include "core/string_ref.h"
32
#include "exprs/vexpr.h"
33
#include "exprs/vexpr_context.h"
34
#include "runtime/runtime_state.h"
35
36
namespace doris {
37
38
213
VExplodeNumbersTableFunction::VExplodeNumbersTableFunction() {
39
213
    _fn_name = "vexplode_numbers";
40
213
}
41
42
121
Status VExplodeNumbersTableFunction::process_init(Block* block, RuntimeState* state) {
43
121
    CHECK(_expr_context->root()->children().size() == 1)
44
0
            << "VExplodeNumbersTableFunction must be have 1 children but have "
45
0
            << _expr_context->root()->children().size();
46
47
121
    RETURN_IF_ERROR(_expr_context->root()->children()[0]->execute_column(
48
121
            _expr_context.get(), block, nullptr, block->rows(), _value_column));
49
121
    if (is_column_const(*_value_column)) {
50
80
        _cur_size = 0;
51
52
        // the argument columns -> Int32
53
80
        const auto& column_nested =
54
80
                assert_cast<const ColumnConst&>(*_value_column).get_data_column_ptr();
55
80
        if (column_nested->is_nullable()) {
56
1
            if (!column_nested->is_null_at(0)) {
57
0
                _cur_size = assert_cast<const ColumnInt32*>(
58
0
                                    assert_cast<const ColumnNullable*>(column_nested.get())
59
0
                                            ->get_nested_column_ptr()
60
0
                                            .get())
61
0
                                    ->get_element(0);
62
0
            }
63
79
        } else {
64
79
            _cur_size = assert_cast<const ColumnInt32*>(column_nested.get())->get_element(0);
65
79
        }
66
67
80
        ((ColumnInt32*)_elements_column.get())->clear();
68
        //_cur_size may be a negative number
69
80
        _cur_size = std::max(static_cast<int64_t>(0L), _cur_size);
70
80
        if (_cur_size &&
71
80
            _cur_size <= state->batch_size()) { // avoid elements_column too big or empty
72
71
            _is_const = true;                   // use const optimize
73
35.4k
            for (int i = 0; i < _cur_size; i++) {
74
35.3k
                ((ColumnInt32*)_elements_column.get())->insert_value(i);
75
35.3k
            }
76
71
        }
77
80
    }
78
121
    return Status::OK();
79
121
}
80
81
228
void VExplodeNumbersTableFunction::process_row(size_t row_idx) {
82
228
    TableFunction::process_row(row_idx);
83
228
    if (_is_const) {
84
140
        return;
85
140
    }
86
87
88
    StringRef value = _value_column->get_data_at(row_idx);
88
88
    if (value.data != nullptr) {
89
84
        _cur_size = std::max(0, *reinterpret_cast<const int*>(value.data));
90
84
    }
91
88
}
92
93
120
void VExplodeNumbersTableFunction::process_close() {
94
120
    _value_column = nullptr;
95
120
}
96
97
43
void VExplodeNumbersTableFunction::get_same_many_values(MutableColumnPtr& column, int length) {
98
43
    if (current_empty()) {
99
0
        column->insert_many_defaults(length);
100
43
    } else {
101
        // for explode numbers, the argument is int32. so cast is safe.
102
43
        if (_is_nullable) {
103
43
            assert_cast<ColumnInt32*>(
104
43
                    assert_cast<ColumnNullable*>(column.get())->get_nested_column_ptr().get())
105
43
                    ->insert_many_vals(static_cast<int32_t>(_cur_offset), length);
106
43
            assert_cast<ColumnUInt8*>(
107
43
                    assert_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
108
43
                    ->insert_many_defaults(length);
109
43
        } else {
110
0
            assert_cast<ColumnInt32*>(column.get())
111
0
                    ->insert_many_vals(static_cast<int32_t>(_cur_offset), length);
112
0
        }
113
43
    }
114
43
}
115
116
} // namespace doris