25
25
#include " common/config.h"
26
26
#include " exec/rowid_fetcher.h"
27
27
#include " pipeline/exec/operator.h"
28
- #include " runtime/buffer_control_block.h"
29
28
#include " runtime/exec_env.h"
29
+ #include " runtime/result_block_buffer.h"
30
30
#include " runtime/result_buffer_mgr.h"
31
31
#include " util/arrow/row_batch.h"
32
32
#include " vec/exprs/vexpr.h"
@@ -48,24 +48,23 @@ Status ResultSinkLocalState::init(RuntimeState* state, LocalSinkStateInfo& info)
48
48
auto fragment_instance_id = state->fragment_instance_id ();
49
49
50
50
auto & p = _parent->cast <ResultSinkOperatorX>();
51
- if (state->query_options ().enable_parallel_result_sink ) {
52
- _sender = _parent->cast <ResultSinkOperatorX>()._sender ;
53
- } else {
54
- RETURN_IF_ERROR (state->exec_env ()->result_mgr ()->create_sender (
55
- fragment_instance_id, p._result_sink_buffer_size_rows , &_sender, state));
56
- }
57
- _sender->set_dependency (fragment_instance_id, _dependency->shared_from_this ());
58
-
59
51
_output_vexpr_ctxs.resize (p._output_vexpr_ctxs .size ());
60
52
for (size_t i = 0 ; i < _output_vexpr_ctxs.size (); i++) {
61
53
RETURN_IF_ERROR (p._output_vexpr_ctxs [i]->clone (state, _output_vexpr_ctxs[i]));
62
54
}
63
- if (p._sink_type == TResultSinkType::ARROW_FLIGHT_PROTOCAL) {
55
+ if (state->query_options ().enable_parallel_result_sink ) {
56
+ _sender = _parent->cast <ResultSinkOperatorX>()._sender ;
57
+ } else {
64
58
std::shared_ptr<arrow::Schema> arrow_schema;
65
- RETURN_IF_ERROR (get_arrow_schema_from_expr_ctxs (_output_vexpr_ctxs, &arrow_schema,
66
- state->timezone ()));
67
- _sender->register_arrow_schema (arrow_schema);
59
+ if (p._sink_type == TResultSinkType::ARROW_FLIGHT_PROTOCAL) {
60
+ RETURN_IF_ERROR (get_arrow_schema_from_expr_ctxs (_output_vexpr_ctxs, &arrow_schema,
61
+ state->timezone ()));
62
+ }
63
+ RETURN_IF_ERROR (state->exec_env ()->result_mgr ()->create_sender (
64
+ fragment_instance_id, p._result_sink_buffer_size_rows , &_sender, state,
65
+ p._sink_type == TResultSinkType::ARROW_FLIGHT_PROTOCAL, arrow_schema));
68
66
}
67
+ _sender->set_dependency (fragment_instance_id, _dependency->shared_from_this ());
69
68
return Status::OK ();
70
69
}
71
70
@@ -79,16 +78,16 @@ Status ResultSinkLocalState::open(RuntimeState* state) {
79
78
case TResultSinkType::MYSQL_PROTOCAL: {
80
79
if (state->mysql_row_binary_format ()) {
81
80
_writer.reset (new (std::nothrow) vectorized::VMysqlResultWriter<true >(
82
- _sender. get () , _output_vexpr_ctxs, _profile));
81
+ _sender, _output_vexpr_ctxs, _profile));
83
82
} else {
84
83
_writer.reset (new (std::nothrow) vectorized::VMysqlResultWriter<false >(
85
- _sender. get () , _output_vexpr_ctxs, _profile));
84
+ _sender, _output_vexpr_ctxs, _profile));
86
85
}
87
86
break ;
88
87
}
89
88
case TResultSinkType::ARROW_FLIGHT_PROTOCAL: {
90
89
_writer.reset (new (std::nothrow) vectorized::VArrowFlightResultWriter (
91
- _sender. get () , _output_vexpr_ctxs, _profile));
90
+ _sender, _output_vexpr_ctxs, _profile));
92
91
break ;
93
92
}
94
93
default :
@@ -102,18 +101,16 @@ Status ResultSinkLocalState::open(RuntimeState* state) {
102
101
ResultSinkOperatorX::ResultSinkOperatorX (int operator_id, const RowDescriptor& row_desc,
103
102
const std::vector<TExpr>& t_output_expr,
104
103
const TResultSink& sink)
105
- : DataSinkOperatorX(operator_id, 0 , 0 ), _row_desc(row_desc), _t_output_expr(t_output_expr) {
106
- if (!sink.__isset .type || sink.type == TResultSinkType::MYSQL_PROTOCAL) {
107
- _sink_type = TResultSinkType::MYSQL_PROTOCAL;
108
- } else {
109
- _sink_type = sink.type ;
110
- }
111
- if (_sink_type == TResultSinkType::ARROW_FLIGHT_PROTOCAL) {
112
- _result_sink_buffer_size_rows = config::arrow_flight_result_sink_buffer_size_rows;
113
- } else {
114
- _result_sink_buffer_size_rows = RESULT_SINK_BUFFER_SIZE;
115
- }
116
- _fetch_option = sink.fetch_option ;
104
+ : DataSinkOperatorX(operator_id, 0 , 0 ),
105
+ _sink_type (!sink.__isset.type || sink.type == TResultSinkType::MYSQL_PROTOCAL
106
+ ? TResultSinkType::MYSQL_PROTOCAL
107
+ : sink.type),
108
+ _result_sink_buffer_size_rows(_sink_type == TResultSinkType::ARROW_FLIGHT_PROTOCAL
109
+ ? config::arrow_flight_result_sink_buffer_size_rows
110
+ : RESULT_SINK_BUFFER_SIZE),
111
+ _row_desc(row_desc),
112
+ _t_output_expr(t_output_expr),
113
+ _fetch_option(sink.fetch_option) {
117
114
_name = " ResultSink" ;
118
115
}
119
116
@@ -132,8 +129,14 @@ Status ResultSinkOperatorX::prepare(RuntimeState* state) {
132
129
RETURN_IF_ERROR (vectorized::VExpr::prepare (_output_vexpr_ctxs, state, _row_desc));
133
130
134
131
if (state->query_options ().enable_parallel_result_sink ) {
132
+ std::shared_ptr<arrow::Schema> arrow_schema;
133
+ if (_sink_type == TResultSinkType::ARROW_FLIGHT_PROTOCAL) {
134
+ RETURN_IF_ERROR (get_arrow_schema_from_expr_ctxs (_output_vexpr_ctxs, &arrow_schema,
135
+ state->timezone ()));
136
+ }
135
137
RETURN_IF_ERROR (state->exec_env ()->result_mgr ()->create_sender (
136
- state->query_id (), _result_sink_buffer_size_rows, &_sender, state));
138
+ state->query_id (), _result_sink_buffer_size_rows, &_sender, state,
139
+ _sink_type == TResultSinkType::ARROW_FLIGHT_PROTOCAL, arrow_schema));
137
140
}
138
141
return vectorized::VExpr::open (_output_vexpr_ctxs, state);
139
142
}
@@ -197,13 +200,13 @@ Status ResultSinkLocalState::close(RuntimeState* state, Status exec_status) {
197
200
198
201
// close sender, this is normal path end
199
202
if (_sender) {
203
+ int64_t written_rows = 0 ;
200
204
if (_writer) {
201
- int64_t written_rows = _writer->get_written_rows ();
202
- _sender->update_return_rows (written_rows);
205
+ written_rows = _writer->get_written_rows ();
203
206
state->get_query_ctx ()->resource_ctx ()->io_context ()->update_returned_rows (
204
207
written_rows);
205
208
}
206
- RETURN_IF_ERROR (_sender->close (state->fragment_instance_id (), final_status));
209
+ RETURN_IF_ERROR (_sender->close (state->fragment_instance_id (), final_status, written_rows ));
207
210
}
208
211
state->exec_env ()->result_mgr ()->cancel_at_time (
209
212
time (nullptr ) + config::result_buffer_cancelled_interval_time,
0 commit comments