forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatagen_operator.cpp
More file actions
114 lines (101 loc) · 4.43 KB
/
Copy pathdatagen_operator.cpp
File metadata and controls
114 lines (101 loc) · 4.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
#include "exec/operator/datagen_operator.h"
#include <memory>
#include "exec/common/data_gen_functions/vdata_gen_function_inf.h"
#include "exec/common/data_gen_functions/vnumbers_tvf.h"
#include "exec/operator/operator.h"
#include "exec/runtime_filter/runtime_filter_consumer.h"
#include "runtime/runtime_profile.h"
namespace doris {
class RuntimeState;
} // namespace doris
namespace doris {
DataGenSourceOperatorX::DataGenSourceOperatorX(ObjectPool* pool, const TPlanNode& tnode,
int operator_id, const DescriptorTbl& descs)
: OperatorX<DataGenLocalState>(pool, tnode, operator_id, descs),
_tuple_id(tnode.data_gen_scan_node.tuple_id),
_tuple_desc(nullptr),
_runtime_filter_descs(tnode.runtime_filters) {}
Status DataGenSourceOperatorX::init(const TPlanNode& tnode, RuntimeState* state) {
RETURN_IF_ERROR(OperatorX<DataGenLocalState>::init(tnode, state));
// set _table_func here
switch (tnode.data_gen_scan_node.func_name) {
case TDataGenFunctionName::NUMBERS:
break;
default:
return Status::InternalError("Unsupported function type");
}
return Status::OK();
}
Status DataGenSourceOperatorX::prepare(RuntimeState* state) {
RETURN_IF_ERROR(OperatorX<DataGenLocalState>::prepare(state));
// get tuple desc
_tuple_desc = state->desc_tbl().get_tuple_descriptor(_tuple_id);
if (nullptr == _tuple_desc) {
return Status::InternalError("Failed to get tuple descriptor.");
}
return Status::OK();
}
Status DataGenSourceOperatorX::get_block_impl(RuntimeState* state, Block* block, bool* eos) {
if (state == nullptr || block == nullptr) {
return Status::InternalError("input is NULL pointer");
}
RETURN_IF_CANCELLED(state);
auto& local_state = get_local_state(state);
SCOPED_TIMER(local_state.exec_time_counter());
SCOPED_PEAK_MEM(&local_state.estimate_memory_usage());
{
SCOPED_TIMER(local_state._table_function_execution_timer);
RETURN_IF_ERROR(local_state._table_func->get_next(state, block, eos));
}
{
SCOPED_TIMER(local_state._filter_timer);
RETURN_IF_ERROR(
VExprContext::filter_block(local_state._conjuncts, block, block->columns()));
}
local_state.reached_limit(block, eos);
return Status::OK();
}
Status DataGenLocalState::init(RuntimeState* state, LocalStateInfo& info) {
SCOPED_TIMER(exec_time_counter());
SCOPED_TIMER(_init_timer);
RETURN_IF_ERROR(PipelineXLocalState<>::init(state, info));
_table_function_execution_timer = ADD_TIMER(custom_profile(), "TableFunctionExecutionTime");
_filter_timer = ADD_TIMER(custom_profile(), "FilterTime");
auto& p = _parent->cast<DataGenSourceOperatorX>();
_table_func = std::make_shared<VNumbersTVF>(p._tuple_id, p._tuple_desc);
_table_func->set_tuple_desc(p._tuple_desc);
RETURN_IF_ERROR(_table_func->set_scan_ranges(info.scan_ranges));
// TODO: use runtime filter to filte result block, maybe this node need derive from vscan_node.
for (const auto& filter_desc : p._runtime_filter_descs) {
std::shared_ptr<RuntimeFilterConsumer> filter;
RETURN_IF_ERROR(state->register_consumer_runtime_filter(filter_desc, p.is_serial_operator(),
p.node_id(), &filter));
}
return Status::OK();
}
Status DataGenLocalState::close(RuntimeState* state) {
SCOPED_TIMER(exec_time_counter());
SCOPED_TIMER(_close_timer);
if (_closed) {
return Status::OK();
}
RETURN_IF_ERROR(_table_func->close(state));
return PipelineXLocalState<>::close(state);
}
} // namespace doris