/root/doris/be/src/exprs/vslot_ref.cpp
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 | | #include "exprs/vslot_ref.h" |
19 | | |
20 | | #include <gen_cpp/Exprs_types.h> |
21 | | #include <glog/logging.h> |
22 | | |
23 | | #include <ostream> |
24 | | |
25 | | #include "common/status.h" |
26 | | #include "core/block/block.h" |
27 | | #include "exprs/vexpr_context.h" |
28 | | #include "runtime/descriptors.h" |
29 | | #include "runtime/runtime_state.h" |
30 | | |
31 | | namespace doris { |
32 | | class VExprContext; |
33 | | |
34 | | VSlotRef::VSlotRef(const doris::TExprNode& node) |
35 | 400k | : VExpr(node), |
36 | 400k | _slot_id(node.slot_ref.slot_id), |
37 | 400k | _column_id(-1), |
38 | 400k | _column_name(nullptr), |
39 | 400k | _column_label(node.label) {} |
40 | | |
41 | | VSlotRef::VSlotRef(const SlotDescriptor* desc) |
42 | 0 | : VExpr(desc->type(), true), _slot_id(desc->id()), _column_id(-1), _column_name(nullptr) {} |
43 | | |
44 | | Status VSlotRef::prepare(doris::RuntimeState* state, const doris::RowDescriptor& desc, |
45 | 258k | VExprContext* context) { |
46 | 258k | RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context)); |
47 | 258k | DCHECK_EQ(_children.size(), 0); |
48 | 258k | if (_slot_id == -1) { |
49 | 0 | _prepare_finished = true; |
50 | 0 | return Status::OK(); |
51 | 0 | } |
52 | 258k | const SlotDescriptor* slot_desc = state->desc_tbl().get_slot_descriptor(_slot_id); |
53 | 258k | if (slot_desc == nullptr) { |
54 | 0 | return Status::Error<ErrorCode::INTERNAL_ERROR>( |
55 | 0 | "couldn't resolve slot descriptor {}, desc: {}", _slot_id, |
56 | 0 | state->desc_tbl().debug_string()); |
57 | 0 | } |
58 | 258k | _column_name = &slot_desc->col_name(); |
59 | 258k | _column_uniq_id = slot_desc->col_unique_id(); |
60 | 258k | _column_id = desc.get_column_id(_slot_id); |
61 | 258k | if (_column_id < 0) { |
62 | 0 | return Status::Error<ErrorCode::INTERNAL_ERROR>( |
63 | 0 | "VSlotRef {} have invalid slot id: {}, desc: {}, slot_desc: {}, desc_tbl: {}", |
64 | 0 | *_column_name, _slot_id, desc.debug_string(), slot_desc->debug_string(), |
65 | 0 | state->desc_tbl().debug_string()); |
66 | 0 | } |
67 | 258k | _prepare_finished = true; |
68 | 258k | return Status::OK(); |
69 | 258k | } |
70 | | |
71 | | Status VSlotRef::open(RuntimeState* state, VExprContext* context, |
72 | 512k | FunctionContext::FunctionStateScope scope) { |
73 | 512k | DCHECK(_prepare_finished); |
74 | 512k | RETURN_IF_ERROR(VExpr::open(state, context, scope)); |
75 | 512k | _open_finished = true; |
76 | 512k | return Status::OK(); |
77 | 512k | } |
78 | | |
79 | 188k | Status VSlotRef::execute(VExprContext* context, Block* block, int* result_column_id) const { |
80 | 188k | if (_column_id >= 0 && _column_id >= block->columns()) { |
81 | 0 | return Status::Error<ErrorCode::INTERNAL_ERROR>( |
82 | 0 | "input block not contain slot column {}, column_id={}, block={}", *_column_name, |
83 | 0 | _column_id, block->dump_structure()); |
84 | 0 | } |
85 | 188k | *result_column_id = _column_id; |
86 | 188k | return Status::OK(); |
87 | 188k | } |
88 | | |
89 | | Status VSlotRef::execute_column(VExprContext* context, const Block* block, Selector* selector, |
90 | 301 | size_t count, ColumnPtr& result_column) const { |
91 | 301 | if (_column_id >= 0 && _column_id >= block->columns()) { |
92 | 0 | return Status::Error<ErrorCode::INTERNAL_ERROR>( |
93 | 0 | "input block not contain slot column {}, column_id={}, block={}", *_column_name, |
94 | 0 | _column_id, block->dump_structure()); |
95 | 0 | } |
96 | 301 | result_column = |
97 | 301 | filter_column_with_selector(block->get_by_position(_column_id).column, selector, count); |
98 | 301 | DCHECK_EQ(result_column->size(), count); |
99 | 301 | return Status::OK(); |
100 | 301 | } |
101 | | |
102 | 51 | DataTypePtr VSlotRef::execute_type(const Block* block) const { |
103 | 51 | if (_column_id >= 0 && _column_id >= block->columns()) { |
104 | 0 | throw doris::Exception(ErrorCode::INTERNAL_ERROR, |
105 | 0 | "input block not contain slot column {}, column_id={}, block={}", |
106 | 0 | *_column_name, _column_id, block->dump_structure()); |
107 | 0 | } |
108 | 51 | return block->get_by_position(_column_id).type; |
109 | 51 | } |
110 | | |
111 | 616 | const std::string& VSlotRef::expr_name() const { |
112 | 616 | return *_column_name; |
113 | 616 | } |
114 | 0 | std::string VSlotRef::expr_label() { |
115 | 0 | return _column_label; |
116 | 0 | } |
117 | | |
118 | 5 | std::string VSlotRef::debug_string() const { |
119 | 5 | std::stringstream out; |
120 | 5 | out << "SlotRef(slot_id=" << _slot_id << VExpr::debug_string() << ")"; |
121 | 5 | return out.str(); |
122 | 5 | } |
123 | | |
124 | 0 | bool VSlotRef::equals(const VExpr& other) { |
125 | 0 | if (!VExpr::equals(other)) { |
126 | 0 | return false; |
127 | 0 | } |
128 | 0 | const auto* other_ptr = dynamic_cast<const VSlotRef*>(&other); |
129 | 0 | if (!other_ptr) { |
130 | 0 | return false; |
131 | 0 | } |
132 | 0 | if (this->_slot_id != other_ptr->_slot_id || this->_column_id != other_ptr->_column_id || |
133 | 0 | this->_column_name != other_ptr->_column_name || |
134 | 0 | this->_column_label != other_ptr->_column_label) { |
135 | 0 | return false; |
136 | 0 | } |
137 | 0 | return true; |
138 | 0 | } |
139 | | |
140 | 0 | uint64_t VSlotRef::get_digest(uint64_t seed) const { |
141 | 0 | seed = HashUtil::hash64(&_column_uniq_id, sizeof(int), seed); |
142 | 0 | return HashUtil::hash64(_column_name->c_str(), _column_name->size(), seed); |
143 | 0 | } |
144 | | |
145 | | } // namespace doris |