Coverage Report

Created: 2026-04-10 06:20

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