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