Coverage Report

Created: 2026-04-10 16:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/table_function/vexplode_numbers.h
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
#pragma once
19
20
#include <algorithm>
21
#include <cstddef>
22
23
#include "common/status.h"
24
#include "core/column/column_nullable.h"
25
#include "core/column/column_vector.h"
26
#include "core/data_type/data_type.h"
27
#include "exprs/table_function/table_function.h"
28
29
namespace doris {
30
31
class Block;
32
33
class VExplodeNumbersTableFunction : public TableFunction {
34
    ENABLE_FACTORY_CREATOR(VExplodeNumbersTableFunction);
35
36
public:
37
    VExplodeNumbersTableFunction();
38
255
    ~VExplodeNumbersTableFunction() override = default;
39
40
    Status process_init(Block* block, RuntimeState* state) override;
41
    void process_row(size_t row_idx) override;
42
    void process_close() override;
43
    void get_same_many_values(MutableColumnPtr& column, int length) override;
44
352
    int get_value(MutableColumnPtr& column, int max_step) override {
45
352
        max_step = std::min(max_step, (int)(_cur_size - _cur_offset));
46
352
        if (_is_const) {
47
140
            if (_is_nullable) {
48
99
                static_cast<ColumnInt32*>(
49
99
                        static_cast<ColumnNullable*>(column.get())->get_nested_column_ptr().get())
50
99
                        ->insert_range_from(*_elements_column, _cur_offset, max_step);
51
99
                static_cast<ColumnUInt8*>(
52
99
                        static_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
53
99
                        ->insert_many_defaults(max_step);
54
99
            } else {
55
41
                static_cast<ColumnInt32*>(column.get())
56
41
                        ->insert_range_from(*_elements_column, _cur_offset, max_step);
57
41
            }
58
212
        } else {
59
            // should dispose the empty status, forward one step
60
212
            if (current_empty()) {
61
1
                column->insert_default();
62
1
                max_step = 1;
63
211
            } else {
64
211
                ColumnInt32* target = nullptr;
65
211
                if (_is_nullable) {
66
44
                    target = assert_cast<ColumnInt32*>(assert_cast<ColumnNullable*>(column.get())
67
44
                                                               ->get_nested_column_ptr()
68
44
                                                               .get());
69
44
                    assert_cast<ColumnUInt8*>(assert_cast<ColumnNullable*>(column.get())
70
44
                                                      ->get_null_map_column_ptr()
71
44
                                                      .get())
72
44
                            ->insert_many_defaults(max_step);
73
167
                } else {
74
167
                    target = assert_cast<ColumnInt32*>(column.get());
75
167
                }
76
211
                auto origin_size = target->size();
77
211
                target->resize(origin_size + max_step);
78
211
                std::iota(target->get_data().data() + origin_size,
79
211
                          target->get_data().data() + origin_size + max_step, _cur_offset);
80
211
            }
81
212
        }
82
352
        forward(max_step);
83
352
        return max_step;
84
352
    }
85
86
private:
87
    ColumnPtr _value_column;
88
    ColumnPtr _elements_column = ColumnInt32::create();
89
};
90
91
} // namespace doris