Coverage Report

Created: 2026-04-14 03:58

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