Coverage Report

Created: 2026-03-31 14:00

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
#include "common/compile_check_begin.h"
38
39
239
VExplodeNumbersTableFunction::VExplodeNumbersTableFunction() {
40
239
    _fn_name = "vexplode_numbers";
41
239
}
42
43
109
Status VExplodeNumbersTableFunction::process_init(Block* block, RuntimeState* state) {
44
109
    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
109
    RETURN_IF_ERROR(_expr_context->root()->children()[0]->execute_column(
49
109
            _expr_context.get(), block, nullptr, block->rows(), _value_column));
50
109
    if (is_column_const(*_value_column)) {
51
80
        _cur_size = 0;
52
53
        // the argument columns -> Int32
54
80
        const auto& column_nested =
55
80
                assert_cast<const ColumnConst&>(*_value_column).get_data_column_ptr();
56
80
        if (column_nested->is_nullable()) {
57
1
            if (!column_nested->is_null_at(0)) {
58
0
                _cur_size = assert_cast<const ColumnInt32*>(
59
0
                                    assert_cast<const ColumnNullable*>(column_nested.get())
60
0
                                            ->get_nested_column_ptr()
61
0
                                            .get())
62
0
                                    ->get_element(0);
63
0
            }
64
79
        } else {
65
79
            _cur_size = assert_cast<const ColumnInt32*>(column_nested.get())->get_element(0);
66
79
        }
67
68
80
        ((ColumnInt32*)_elements_column.get())->clear();
69
        //_cur_size may be a negative number
70
80
        _cur_size = std::max(static_cast<int64_t>(0L), _cur_size);
71
80
        if (_cur_size &&
72
80
            _cur_size <= state->batch_size()) { // avoid elements_column too big or empty
73
71
            _is_const = true;                   // use const optimize
74
35.4k
            for (int i = 0; i < _cur_size; i++) {
75
35.3k
                ((ColumnInt32*)_elements_column.get())->insert_value(i);
76
35.3k
            }
77
71
        }
78
80
    }
79
109
    return Status::OK();
80
109
}
81
82
228
void VExplodeNumbersTableFunction::process_row(size_t row_idx) {
83
228
    TableFunction::process_row(row_idx);
84
228
    if (_is_const) {
85
140
        return;
86
140
    }
87
88
88
    StringRef value = _value_column->get_data_at(row_idx);
89
88
    if (value.data != nullptr) {
90
84
        _cur_size = std::max(0, *reinterpret_cast<const int*>(value.data));
91
84
    }
92
88
}
93
94
108
void VExplodeNumbersTableFunction::process_close() {
95
108
    _value_column = nullptr;
96
108
}
97
98
43
void VExplodeNumbersTableFunction::get_same_many_values(MutableColumnPtr& column, int length) {
99
43
    if (current_empty()) {
100
0
        column->insert_many_defaults(length);
101
43
    } else {
102
        // for explode numbers, the argument is int32. so cast is safe.
103
43
        if (_is_nullable) {
104
43
            assert_cast<ColumnInt32*>(
105
43
                    assert_cast<ColumnNullable*>(column.get())->get_nested_column_ptr().get())
106
43
                    ->insert_many_vals(static_cast<int32_t>(_cur_offset), length);
107
43
            assert_cast<ColumnUInt8*>(
108
43
                    assert_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
109
43
                    ->insert_many_defaults(length);
110
43
        } else {
111
0
            assert_cast<ColumnInt32*>(column.get())
112
0
                    ->insert_many_vals(static_cast<int32_t>(_cur_offset), length);
113
0
        }
114
43
    }
115
43
}
116
117
#include "common/compile_check_end.h"
118
} // namespace doris