be/src/exec/sink/writer/vmysql_result_writer.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 <gen_cpp/PaloInternalService_types.h> |
20 | | #include <stddef.h> |
21 | | |
22 | | #include <memory> |
23 | | #include <vector> |
24 | | |
25 | | #include "common/status.h" |
26 | | #include "core/data_type/data_type.h" |
27 | | #include "core/data_type/define_primitive_type.h" |
28 | | #include "exec/sink/writer/result_writer.h" |
29 | | #include "exprs/vexpr_fwd.h" |
30 | | #include "runtime/result_block_buffer.h" |
31 | | #include "runtime/runtime_profile.h" |
32 | | #include "util/mysql_row_buffer.h" |
33 | | |
34 | | namespace doris { |
35 | | #include "common/compile_check_begin.h" |
36 | | class RuntimeState; |
37 | | |
38 | | class Block; |
39 | | |
40 | | class GetResultBatchCtx { |
41 | | public: |
42 | | using ResultType = TFetchDataResult; |
43 | | ENABLE_FACTORY_CREATOR(GetResultBatchCtx) |
44 | | GetResultBatchCtx(PFetchDataResult* result, google::protobuf::Closure* done) |
45 | 1 | : _result(result), _done(done) {} |
46 | | #ifdef BE_TEST |
47 | 3 | GetResultBatchCtx() = default; |
48 | | #endif |
49 | 4 | MOCK_FUNCTION ~GetResultBatchCtx() = default; |
50 | | MOCK_FUNCTION void on_failure(const Status& status); |
51 | | MOCK_FUNCTION void on_close(int64_t packet_seq, int64_t returned_rows = 0); |
52 | | MOCK_FUNCTION Status on_data(const std::shared_ptr<TFetchDataResult>& t_result, |
53 | | int64_t packet_seq, ResultBlockBufferBase* buffer); |
54 | | |
55 | | private: |
56 | | #ifndef BE_TEST |
57 | | const int32_t _max_msg_size = std::numeric_limits<int32_t>::max(); |
58 | | #else |
59 | | int32_t _max_msg_size = std::numeric_limits<int32_t>::max(); |
60 | | #endif |
61 | | |
62 | | PFetchDataResult* _result = nullptr; |
63 | | google::protobuf::Closure* _done = nullptr; |
64 | | }; |
65 | | |
66 | | using MySQLResultBlockBuffer = ResultBlockBuffer<GetResultBatchCtx>; |
67 | | |
68 | | class VMysqlResultWriter final : public ResultWriter { |
69 | | public: |
70 | | VMysqlResultWriter(std::shared_ptr<ResultBlockBufferBase> sinker, |
71 | | const VExprContextSPtrs& output_vexpr_ctxs, RuntimeProfile* parent_profile, |
72 | | bool is_binary_format); |
73 | | |
74 | | Status init(RuntimeState* state) override; |
75 | | |
76 | | Status write(RuntimeState* state, Block& block) override; |
77 | | |
78 | | Status close(Status status) override; |
79 | | |
80 | | private: |
81 | | void _init_profile(); |
82 | | Status _write_one_block(RuntimeState* state, Block& block); |
83 | | |
84 | | std::shared_ptr<MySQLResultBlockBuffer> _sinker = nullptr; |
85 | | |
86 | | const VExprContextSPtrs& _output_vexpr_ctxs; |
87 | | |
88 | | RuntimeProfile* _parent_profile; // parent profile from result sink. not owned |
89 | | // total time cost on append batch operation |
90 | | RuntimeProfile::Counter* _append_row_batch_timer = nullptr; |
91 | | // tuple convert timer, child timer of _append_row_batch_timer |
92 | | RuntimeProfile::Counter* _convert_tuple_timer = nullptr; |
93 | | // file write timer, child timer of _append_row_batch_timer |
94 | | RuntimeProfile::Counter* _result_send_timer = nullptr; |
95 | | // number of sent rows |
96 | | RuntimeProfile::Counter* _sent_rows_counter = nullptr; |
97 | | // size of sent data |
98 | | RuntimeProfile::Counter* _bytes_sent_counter = nullptr; |
99 | | // If true, no block will be sent |
100 | | bool _is_dry_run = false; |
101 | | |
102 | | uint64_t _bytes_sent = 0; |
103 | | |
104 | | const bool _is_binary_format; |
105 | | }; |
106 | | } // namespace doris |
107 | | |
108 | | #include "common/compile_check_end.h" |