Coverage Report

Created: 2026-04-10 12:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/table_function/table_function.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 <fmt/core.h>
21
22
#include <cstddef>
23
#include <cstdint>
24
25
#include "common/status.h"
26
#include "core/block/block.h"
27
#include "exprs/vexpr_context.h"
28
29
namespace doris {
30
31
constexpr auto COMBINATOR_SUFFIX_OUTER = "_outer";
32
33
class TableFunction {
34
public:
35
6.17k
    virtual ~TableFunction() = default;
36
37
    struct BlockFastPathContext {
38
        const UInt8* array_nullmap_data = nullptr;
39
        const IColumn::Offsets64* offsets_ptr = nullptr;
40
        ColumnPtr nested_col = nullptr;
41
        const UInt8* nested_nullmap_data = nullptr;
42
        bool generate_row_index = false;
43
    };
44
45
955
    virtual Status prepare() { return Status::OK(); }
46
47
3.63k
    virtual Status open() { return Status::OK(); }
48
49
    virtual Status process_init(Block* block, RuntimeState* state) = 0;
50
51
3.14k
    virtual void process_row(size_t row_idx) {
52
3.14k
        if (!_is_const) {
53
2.98k
            _cur_size = 0;
54
2.98k
        }
55
3.14k
        reset();
56
3.14k
    }
57
58
    // only used for vectorized.
59
    virtual void process_close() = 0;
60
61
3.00k
    virtual void reset() {
62
3.00k
        _eos = false;
63
3.00k
        _cur_offset = 0;
64
3.00k
    }
65
66
    virtual void get_same_many_values(MutableColumnPtr& column, int length = 0) = 0;
67
    virtual int get_value(MutableColumnPtr& column, int max_step) = 0;
68
69
1.10k
    virtual bool support_block_fast_path() const { return false; }
70
    virtual Status prepare_block_fast_path(Block* /*block*/, RuntimeState* /*state*/,
71
0
                                           BlockFastPathContext* /*ctx*/) {
72
0
        return Status::NotSupported("table function {} doesn't support block fast path", _fn_name);
73
0
    }
74
75
11.6k
    virtual Status close() { return Status::OK(); }
76
77
2.60k
    virtual void forward(int step = 1) {
78
2.60k
        if (current_empty()) {
79
95
            _eos = true;
80
2.50k
        } else {
81
2.50k
            _cur_offset += step;
82
2.50k
            if (_cur_offset >= _cur_size) {
83
2.17k
                _eos = true;
84
2.17k
            }
85
2.50k
        }
86
2.60k
    }
87
88
0
    std::string name() const { return _fn_name; }
89
4.09k
    bool eos() const { return _eos; }
90
91
6.14k
    void set_expr_context(const VExprContextSPtr& expr_context) { _expr_context = expr_context; }
92
6.29k
    void set_nullable() { _is_nullable = true; }
93
94
5.50k
    bool is_outer() const { return _is_outer; }
95
1.28k
    void set_outer() {
96
1.28k
        if (is_outer()) {
97
0
            return;
98
0
        }
99
1.28k
        _is_outer = true;
100
1.28k
        _fn_name += COMBINATOR_SUFFIX_OUTER;
101
1.28k
    }
102
103
7.53k
    bool current_empty() const { return _cur_size == 0; }
104
105
protected:
106
    std::string _fn_name;
107
    VExprContextSPtr _expr_context = nullptr;
108
    // true if there is no more data can be read from this function.
109
    bool _eos = false;
110
    // the position of current cursor
111
    int64_t _cur_offset = 0;
112
    // the size of current result
113
    int64_t _cur_size = 0;
114
    // set _is_outer to false for explode function, and should not return tuple while array is null or empty
115
    bool _is_outer = false;
116
117
    bool _is_nullable = false;
118
    bool _is_const = false;
119
};
120
121
} // namespace doris