/root/doris/be/src/exec/data_sink.h
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 | | // This file is copied from |
18 | | // https://github.com/apache/impala/blob/branch-2.9.0/be/src/exec/data-sink.h |
19 | | // and modified by Doris |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <stddef.h> |
24 | | |
25 | | #include <memory> |
26 | | #include <string> |
27 | | #include <vector> |
28 | | |
29 | | #include "common/status.h" |
30 | | #include "runtime/descriptors.h" |
31 | | #include "util/runtime_profile.h" |
32 | | |
33 | | namespace doris { |
34 | | |
35 | | class ObjectPool; |
36 | | class RuntimeState; |
37 | | class TPlanFragmentExecParams; |
38 | | class DescriptorTbl; |
39 | | class TDataSink; |
40 | | class TExpr; |
41 | | class TPipelineFragmentParams; |
42 | | class TOlapTableSink; |
43 | | class QueryStatistics; |
44 | | |
45 | | namespace vectorized { |
46 | | class Block; |
47 | | } |
48 | | |
49 | | // Superclass of all data sinks. |
50 | | class DataSink { |
51 | | public: |
52 | | DataSink(const RowDescriptor& desc); |
53 | 5 | virtual ~DataSink() {} |
54 | | |
55 | | virtual Status init(const TDataSink& thrift_sink); |
56 | | |
57 | | // Setup. Call before send(), Open(), or Close(). |
58 | | // Subclasses must call DataSink::Prepare(). |
59 | | virtual Status prepare(RuntimeState* state); |
60 | | |
61 | | // Setup. Call before send() or close(). |
62 | | virtual Status open(RuntimeState* state) = 0; |
63 | | |
64 | | // Send a Block into this sink. |
65 | 0 | virtual Status send(RuntimeState* state, vectorized::Block* block, bool eos = false) { |
66 | 0 | return Status::NotSupported("Not support send block"); |
67 | 0 | } |
68 | | |
69 | | // Send a Block into this sink, not blocked thredd API only use in pipeline exec engine |
70 | 0 | virtual Status sink(RuntimeState* state, vectorized::Block* block, bool eos = false) { |
71 | 0 | return send(state, block, eos); |
72 | 0 | } |
73 | | |
74 | 0 | [[nodiscard]] virtual bool is_pending_finish() const { return false; } |
75 | | |
76 | | // Releases all resources that were allocated in prepare()/send(). |
77 | | // Further send() calls are illegal after calling close(). |
78 | | // It must be okay to call this multiple times. Subsequent calls should |
79 | | // be ignored. |
80 | 4 | virtual Status close(RuntimeState* state, Status exec_status) { |
81 | 4 | _closed = true; |
82 | 4 | return Status::OK(); |
83 | 4 | } |
84 | | |
85 | | // Creates a new data sink from thrift_sink. A pointer to the |
86 | | // new sink is written to *sink, and is owned by the caller. |
87 | | static Status create_data_sink(ObjectPool* pool, const TDataSink& thrift_sink, |
88 | | const std::vector<TExpr>& output_exprs, |
89 | | const TPlanFragmentExecParams& params, |
90 | | const RowDescriptor& row_desc, RuntimeState* state, |
91 | | std::unique_ptr<DataSink>* sink, DescriptorTbl& desc_tbl); |
92 | | |
93 | | static Status create_data_sink(ObjectPool* pool, const TDataSink& thrift_sink, |
94 | | const std::vector<TExpr>& output_exprs, |
95 | | const TPipelineFragmentParams& params, |
96 | | const size_t& local_param_idx, const RowDescriptor& row_desc, |
97 | | RuntimeState* state, std::unique_ptr<DataSink>* sink, |
98 | | DescriptorTbl& desc_tbl); |
99 | | |
100 | | // Returns the runtime profile for the sink. |
101 | 0 | RuntimeProfile* profile() { return _profile; } |
102 | | |
103 | 0 | const RowDescriptor& row_desc() { return _row_desc; } |
104 | | |
105 | 0 | virtual bool can_write() { return true; } |
106 | | |
107 | | std::shared_ptr<QueryStatistics> get_query_statistics_ptr(); |
108 | | |
109 | | protected: |
110 | | // Set to true after close() has been called. subclasses should check and set this in |
111 | | // close(). |
112 | | bool _closed = false; |
113 | | std::string _name; |
114 | | const RowDescriptor& _row_desc; |
115 | | |
116 | | RuntimeProfile* _profile = nullptr; // Allocated from _pool |
117 | | |
118 | | RuntimeProfile::Counter* _exec_timer = nullptr; |
119 | | RuntimeProfile::Counter* _blocks_sent_counter = nullptr; |
120 | | RuntimeProfile::Counter* _output_rows_counter = nullptr; |
121 | | |
122 | 5 | void init_sink_common_profile() { |
123 | 5 | _exec_timer = ADD_TIMER_WITH_LEVEL(_profile, "ExecTime", 1); |
124 | 5 | _output_rows_counter = ADD_COUNTER_WITH_LEVEL(_profile, "RowsProduced", TUnit::UNIT, 1); |
125 | 5 | _blocks_sent_counter = ADD_COUNTER_WITH_LEVEL(_profile, "BlocksProduced", TUnit::UNIT, 1); |
126 | 5 | } |
127 | | |
128 | | std::shared_ptr<QueryStatistics> _query_statistics = nullptr; |
129 | | }; |
130 | | |
131 | | } // namespace doris |