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 | | |
24 | | #include "common/status.h" |
25 | | #include "core/block/block.h" |
26 | | #include "exprs/vexpr_context.h" |
27 | | |
28 | | namespace doris { |
29 | | #include "common/compile_check_begin.h" |
30 | | |
31 | | constexpr auto COMBINATOR_SUFFIX_OUTER = "_outer"; |
32 | | |
33 | | class TableFunction { |
34 | | public: |
35 | 5.68k | virtual ~TableFunction() = default; |
36 | | |
37 | 885 | virtual Status prepare() { return Status::OK(); } |
38 | | |
39 | 3.17k | virtual Status open() { return Status::OK(); } |
40 | | |
41 | | virtual Status process_init(Block* block, RuntimeState* state) = 0; |
42 | | |
43 | 19.1k | virtual void process_row(size_t row_idx) { |
44 | 19.1k | if (!_is_const) { |
45 | 19.0k | _cur_size = 0; |
46 | 19.0k | } |
47 | 19.1k | reset(); |
48 | 19.1k | } |
49 | | |
50 | | // only used for vectorized. |
51 | | virtual void process_close() = 0; |
52 | | |
53 | 19.0k | virtual void reset() { |
54 | 19.0k | _eos = false; |
55 | 19.0k | _cur_offset = 0; |
56 | 19.0k | } |
57 | | |
58 | | virtual void get_same_many_values(MutableColumnPtr& column, int length = 0) = 0; |
59 | | virtual int get_value(MutableColumnPtr& column, int max_step) = 0; |
60 | | |
61 | 9.97k | virtual Status close() { return Status::OK(); } |
62 | | |
63 | 4.03k | virtual void forward(int step = 1) { |
64 | 4.03k | if (current_empty()) { |
65 | 156 | _eos = true; |
66 | 3.88k | } else { |
67 | 3.88k | _cur_offset += step; |
68 | 3.88k | if (_cur_offset >= _cur_size) { |
69 | 3.54k | _eos = true; |
70 | 3.54k | } |
71 | 3.88k | } |
72 | 4.03k | } |
73 | | |
74 | 0 | std::string name() const { return _fn_name; } |
75 | 21.4k | bool eos() const { return _eos; } |
76 | | |
77 | 5.64k | void set_expr_context(const VExprContextSPtr& expr_context) { _expr_context = expr_context; } |
78 | 5.80k | void set_nullable() { _is_nullable = true; } |
79 | | |
80 | 20.8k | bool is_outer() const { return _is_outer; } |
81 | 942 | void set_outer() { |
82 | 942 | if (is_outer()) { |
83 | 0 | return; |
84 | 0 | } |
85 | 942 | _is_outer = true; |
86 | 942 | _fn_name += COMBINATOR_SUFFIX_OUTER; |
87 | 942 | } |
88 | | |
89 | 27.0k | bool current_empty() const { return _cur_size == 0; } |
90 | | |
91 | | protected: |
92 | | std::string _fn_name; |
93 | | VExprContextSPtr _expr_context = nullptr; |
94 | | // true if there is no more data can be read from this function. |
95 | | bool _eos = false; |
96 | | // the position of current cursor |
97 | | int64_t _cur_offset = 0; |
98 | | // the size of current result |
99 | | int64_t _cur_size = 0; |
100 | | // set _is_outer to false for explode function, and should not return tuple while array is null or empty |
101 | | bool _is_outer = false; |
102 | | |
103 | | bool _is_nullable = false; |
104 | | bool _is_const = false; |
105 | | }; |
106 | | |
107 | | #include "common/compile_check_end.h" |
108 | | } // namespace doris |