/root/doris/be/src/exprs/vcolumn_ref.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 | | #include <atomic> |
20 | | |
21 | | #include "exprs/function/function.h" |
22 | | #include "exprs/vexpr.h" |
23 | | #include "runtime/descriptors.h" |
24 | | #include "runtime/runtime_state.h" |
25 | | |
26 | | namespace doris { |
27 | | class VColumnRef final : public VExpr { |
28 | | ENABLE_FACTORY_CREATOR(VColumnRef); |
29 | | |
30 | | public: |
31 | | //this is different of slotref is using slot_id find a column_id |
32 | | //slotref: need to find the equal id in tuple, then return column_id, the plan of FE is very important |
33 | | //columnref: is columnid = slotid, not used to find, so you should know this column placed in block |
34 | | VColumnRef(const TExprNode& node) |
35 | 0 | : VExpr(node), |
36 | 0 | _column_id(node.column_ref.column_id), |
37 | 0 | _column_name(node.column_ref.column_name) {} |
38 | | |
39 | 0 | Status prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) override { |
40 | 0 | RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context)); |
41 | 0 | DCHECK_EQ(_children.size(), 0); |
42 | 0 | if (_column_id < 0) { |
43 | 0 | return Status::InternalError( |
44 | 0 | "VColumnRef have invalid slot id: {}, _column_name: {}, desc: {}", _column_id, |
45 | 0 | _column_name, desc.debug_string()); |
46 | 0 | } |
47 | 0 | _prepare_finished = true; |
48 | 0 | return Status::OK(); |
49 | 0 | } |
50 | | |
51 | | Status open(RuntimeState* state, VExprContext* context, |
52 | 0 | FunctionContext::FunctionStateScope scope) override { |
53 | 0 | DCHECK(_prepare_finished); |
54 | 0 | RETURN_IF_ERROR(VExpr::open(state, context, scope)); |
55 | 0 | _open_finished = true; |
56 | 0 | return Status::OK(); |
57 | 0 | } |
58 | | |
59 | | Status execute_column(VExprContext* context, const Block* block, Selector* selector, |
60 | 0 | size_t count, ColumnPtr& result_column) const override { |
61 | 0 | DCHECK(_open_finished || block == nullptr); |
62 | 0 | auto origin_column = block->get_by_position(_column_id + _gap).column; |
63 | 0 | result_column = filter_column_with_selector(origin_column, selector, count); |
64 | 0 | return Status::OK(); |
65 | 0 | } |
66 | | |
67 | 0 | DataTypePtr execute_type(const Block* block) const override { |
68 | 0 | DCHECK(_open_finished || block == nullptr); |
69 | 0 | return block->get_by_position(_column_id + _gap).type; |
70 | 0 | } |
71 | | |
72 | 0 | bool is_constant() const override { return false; } |
73 | | |
74 | 0 | int column_id() const { return _column_id; } |
75 | | |
76 | 0 | const std::string& expr_name() const override { return _column_name; } |
77 | | |
78 | 0 | void set_gap(int gap) { |
79 | 0 | if (_gap == 0) { |
80 | 0 | _gap = gap; |
81 | 0 | } |
82 | 0 | } |
83 | | |
84 | 0 | std::string debug_string() const override { |
85 | 0 | std::stringstream out; |
86 | 0 | out << "VColumnRef(slot_id: " << _column_id << ",column_name: " << _column_name |
87 | 0 | << VExpr::debug_string() << ")"; |
88 | 0 | return out.str(); |
89 | 0 | } |
90 | | |
91 | 0 | double execute_cost() const override { return 0.0; } |
92 | | |
93 | | private: |
94 | | int _column_id; |
95 | | std::atomic<int> _gap = 0; |
96 | | std::string _column_name; |
97 | | }; |
98 | | } // namespace doris |