/root/doris/be/src/pipeline/pipeline.cpp
Line | Count | Source (jump to first uncovered line) |
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 "pipeline.h" |
19 | | |
20 | | #include <memory> |
21 | | #include <string> |
22 | | #include <utility> |
23 | | |
24 | | #include "pipeline/exec/operator.h" |
25 | | #include "pipeline/pipeline_task.h" |
26 | | |
27 | | namespace doris::pipeline { |
28 | | |
29 | 0 | void Pipeline::_init_profile() { |
30 | 0 | auto s = fmt::format("Pipeline (pipeline id={})", _pipeline_id); |
31 | 0 | _pipeline_profile = std::make_unique<RuntimeProfile>(std::move(s)); |
32 | 0 | } |
33 | | |
34 | 0 | Status Pipeline::build_operators() { |
35 | 0 | _name.reserve(_operator_builders.size() * 10); |
36 | 0 | _name.append(std::to_string(id())); |
37 | |
|
38 | 0 | OperatorPtr pre; |
39 | 0 | for (auto& operator_t : _operator_builders) { |
40 | 0 | auto o = operator_t->build_operator(); |
41 | 0 | if (pre) { |
42 | 0 | RETURN_IF_ERROR(o->set_child(pre)); |
43 | 0 | } |
44 | 0 | _operators.emplace_back(o); |
45 | |
|
46 | 0 | _name.push_back('-'); |
47 | 0 | _name.append(std::to_string(operator_t->id())); |
48 | 0 | _name.append(o->get_name()); |
49 | |
|
50 | 0 | pre = std::move(o); |
51 | 0 | } |
52 | 0 | return Status::OK(); |
53 | 0 | } |
54 | | |
55 | 0 | Status Pipeline::add_operator(OperatorBuilderPtr& op) { |
56 | 0 | if (_operator_builders.empty() && !op->is_source()) { |
57 | 0 | return Status::InternalError("Should set source before other operator"); |
58 | 0 | } |
59 | 0 | _operator_builders.emplace_back(op); |
60 | 0 | return Status::OK(); |
61 | 0 | } |
62 | | |
63 | 0 | Status Pipeline::add_operator(OperatorXPtr& op) { |
64 | 0 | op->set_parallel_tasks(num_tasks()); |
65 | 0 | operatorXs.emplace_back(op); |
66 | 0 | if (op->is_source()) { |
67 | 0 | std::reverse(operatorXs.begin(), operatorXs.end()); |
68 | 0 | } |
69 | 0 | return Status::OK(); |
70 | 0 | } |
71 | | |
72 | 0 | Status Pipeline::prepare(RuntimeState* state) { |
73 | | // TODO |
74 | 0 | RETURN_IF_ERROR(operatorXs.back()->prepare(state)); |
75 | 0 | RETURN_IF_ERROR(operatorXs.back()->open(state)); |
76 | 0 | RETURN_IF_ERROR(_sink_x->prepare(state)); |
77 | 0 | RETURN_IF_ERROR(_sink_x->open(state)); |
78 | 0 | return Status::OK(); |
79 | 0 | } |
80 | | |
81 | 0 | Status Pipeline::set_sink_builder(OperatorBuilderPtr& sink_) { |
82 | 0 | if (_sink_builder) { |
83 | 0 | return Status::InternalError("set sink twice"); |
84 | 0 | } |
85 | 0 | if (!sink_->is_sink()) { |
86 | 0 | return Status::InternalError("should set a sink operator but {}", typeid(sink_).name()); |
87 | 0 | } |
88 | 0 | _sink_builder = sink_; |
89 | 0 | return Status::OK(); |
90 | 0 | } |
91 | | |
92 | 0 | Status Pipeline::set_sink(DataSinkOperatorXPtr& sink) { |
93 | 0 | if (_sink_x) { |
94 | 0 | return Status::InternalError("set sink twice"); |
95 | 0 | } |
96 | 0 | if (!sink->is_sink()) { |
97 | 0 | return Status::InternalError("should set a sink operator but {}", typeid(sink).name()); |
98 | 0 | } |
99 | 0 | _sink_x = sink; |
100 | 0 | return Status::OK(); |
101 | 0 | } |
102 | | |
103 | 0 | void Pipeline::make_all_runnable() { |
104 | 0 | if (_sink_x->count_down_destination()) { |
105 | 0 | for (auto* task : _tasks) { |
106 | 0 | if (task) { |
107 | 0 | task->clear_blocking_state(true); |
108 | 0 | } |
109 | 0 | } |
110 | 0 | } |
111 | 0 | } |
112 | | |
113 | | } // namespace doris::pipeline |