Coverage Report

Created: 2026-04-10 13:26

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
52
    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
18
    virtual Status prepare() { return Status::OK(); }
47
48
18
    virtual Status open() { return Status::OK(); }
49
50
    virtual Status process_init(Block* block, RuntimeState* state) = 0;
51
52
99
    virtual void process_row(size_t row_idx) {
53
99
        if (!_is_const) {
54
95
            _cur_size = 0;
55
95
        }
56
99
        reset();
57
99
    }
58
59
    // only used for vectorized.
60
    virtual void process_close() = 0;
61
62
109
    virtual void reset() {
63
109
        _eos = false;
64
109
        _cur_offset = 0;
65
109
    }
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
2
    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
0
    virtual Status close() { return Status::OK(); }
77
78
120
    virtual void forward(int step = 1) {
79
120
        if (current_empty()) {
80
21
            _eos = true;
81
99
        } else {
82
99
            _cur_offset += step;
83
99
            if (_cur_offset >= _cur_size) {
84
49
                _eos = true;
85
49
            }
86
99
        }
87
120
    }
88
89
0
    std::string name() const { return _fn_name; }
90
136
    bool eos() const { return _eos; }
91
92
52
    void set_expr_context(const VExprContextSPtr& expr_context) { _expr_context = expr_context; }
93
48
    void set_nullable() { _is_nullable = true; }
94
95
99
    bool is_outer() const { return _is_outer; }
96
10
    void set_outer() {
97
10
        if (is_outer()) {
98
0
            return;
99
0
        }
100
10
        _is_outer = true;
101
10
        _fn_name += COMBINATOR_SUFFIX_OUTER;
102
10
    }
103
104
313
    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