Coverage Report

Created: 2026-03-16 13:13

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
210
    ~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
352
    int get_value(MutableColumnPtr& column, int max_step) override {
46
352
        max_step = std::min(max_step, (int)(_cur_size - _cur_offset));
47
352
        if (_is_const) {
48
140
            if (_is_nullable) {
49
99
                static_cast<ColumnInt32*>(
50
99
                        static_cast<ColumnNullable*>(column.get())->get_nested_column_ptr().get())
51
99
                        ->insert_range_from(*_elements_column, _cur_offset, max_step);
52
99
                static_cast<ColumnUInt8*>(
53
99
                        static_cast<ColumnNullable*>(column.get())->get_null_map_column_ptr().get())
54
99
                        ->insert_many_defaults(max_step);
55
99
            } else {
56
41
                static_cast<ColumnInt32*>(column.get())
57
41
                        ->insert_range_from(*_elements_column, _cur_offset, max_step);
58
41
            }
59
212
        } else {
60
            // should dispose the empty status, forward one step
61
212
            if (current_empty()) {
62
1
                column->insert_default();
63
1
                max_step = 1;
64
211
            } else {
65
211
                ColumnInt32* target = nullptr;
66
211
                if (_is_nullable) {
67
44
                    target = assert_cast<ColumnInt32*>(assert_cast<ColumnNullable*>(column.get())
68
44
                                                               ->get_nested_column_ptr()
69
44
                                                               .get());
70
44
                    assert_cast<ColumnUInt8*>(assert_cast<ColumnNullable*>(column.get())
71
44
                                                      ->get_null_map_column_ptr()
72
44
                                                      .get())
73
44
                            ->insert_many_defaults(max_step);
74
167
                } else {
75
167
                    target = assert_cast<ColumnInt32*>(column.get());
76
167
                }
77
211
                auto origin_size = target->size();
78
211
                target->resize(origin_size + max_step);
79
211
                std::iota(target->get_data().data() + origin_size,
80
211
                          target->get_data().data() + origin_size + max_step, _cur_offset);
81
211
            }
82
212
        }
83
352
        forward(max_step);
84
352
        return max_step;
85
352
    }
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