Coverage Report

Created: 2026-03-15 01:14

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
#include "common/compile_check_begin.h"
31
32
class Block;
33
34
class VExplodeNumbersTableFunction : public TableFunction {
35
    ENABLE_FACTORY_CREATOR(VExplodeNumbersTableFunction);
36
37
public:
38
    VExplodeNumbersTableFunction();
39
1
    ~VExplodeNumbersTableFunction() override = default;
40
41
    Status process_init(Block* block, RuntimeState* state) override;
42
    void process_row(size_t row_idx) override;
43
    void process_close() override;
44
    void get_same_many_values(MutableColumnPtr& column, int length) override;
45
0
    int get_value(MutableColumnPtr& column, int max_step) override {
46
0
        max_step = std::min(max_step, (int)(_cur_size - _cur_offset));
47
0
        if (_is_const) {
48
0
            if (_is_nullable) {
49
0
                static_cast<ColumnInt32*>(
50
0
                        static_cast<ColumnNullable*>(column.get())->get_nested_column_ptr().get())
51
0
                        ->insert_range_from(*_elements_column, _cur_offset, max_step);
52
0
                static_cast<ColumnUInt8*>(
53
0
                        static_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
54
0
                        ->insert_many_defaults(max_step);
55
0
            } else {
56
0
                static_cast<ColumnInt32*>(column.get())
57
0
                        ->insert_range_from(*_elements_column, _cur_offset, max_step);
58
0
            }
59
0
        } else {
60
            // should dispose the empty status, forward one step
61
0
            if (current_empty()) {
62
0
                column->insert_default();
63
0
                max_step = 1;
64
0
            } else {
65
0
                ColumnInt32* target = nullptr;
66
0
                if (_is_nullable) {
67
0
                    target = assert_cast<ColumnInt32*>(assert_cast<ColumnNullable*>(column.get())
68
0
                                                               ->get_nested_column_ptr()
69
0
                                                               .get());
70
0
                    assert_cast<ColumnUInt8*>(assert_cast<ColumnNullable*>(column.get())
71
0
                                                      ->get_null_map_column_ptr()
72
0
                                                      .get())
73
0
                            ->insert_many_defaults(max_step);
74
0
                } else {
75
0
                    target = assert_cast<ColumnInt32*>(column.get());
76
0
                }
77
0
                auto origin_size = target->size();
78
0
                target->resize(origin_size + max_step);
79
0
                std::iota(target->get_data().data() + origin_size,
80
0
                          target->get_data().data() + origin_size + max_step, _cur_offset);
81
0
            }
82
0
        }
83
0
        forward(max_step);
84
0
        return max_step;
85
0
    }
86
87
private:
88
    ColumnPtr _value_column;
89
    ColumnPtr _elements_column = ColumnInt32::create();
90
};
91
92
#include "common/compile_check_end.h"
93
} // namespace doris