51
51
#include " exec/schema_scanner/schema_workload_groups_scanner.h"
52
52
#include " exec/schema_scanner/schema_workload_sched_policy_scanner.h"
53
53
#include " olap/hll.h"
54
+ #include " pipeline/dependency.h"
54
55
#include " runtime/define_primitive_type.h"
56
+ #include " runtime/fragment_mgr.h"
57
+ #include " runtime/types.h"
55
58
#include " util/string_util.h"
56
59
#include " util/types.h"
57
60
#include " vec/columns/column.h"
65
68
#include " vec/core/column_with_type_and_name.h"
66
69
#include " vec/core/types.h"
67
70
#include " vec/data_types/data_type.h"
71
+ #include " vec/data_types/data_type_factory.hpp"
68
72
69
73
namespace doris {
70
74
class ObjectPool ;
@@ -85,7 +89,60 @@ Status SchemaScanner::start(RuntimeState* state) {
85
89
return Status::OK ();
86
90
}
87
91
88
- Status SchemaScanner::get_next_block (vectorized::Block* block, bool * eos) {
92
+ Status SchemaScanner::get_next_block (RuntimeState* state, vectorized::Block* block, bool * eos) {
93
+ if (_data_block == nullptr ) {
94
+ return Status::InternalError (" No data left!" );
95
+ }
96
+ DCHECK (_async_thread_running == false );
97
+ RETURN_IF_ERROR (_scanner_status.status ());
98
+ for (size_t i = 0 ; i < block->columns (); i++) {
99
+ std::move (*block->get_by_position (i).column )
100
+ .mutate ()
101
+ ->insert_range_from (*_data_block->get_by_position (i).column , 0 ,
102
+ _data_block->rows ());
103
+ }
104
+ _data_block->clear_column_data ();
105
+ *eos = _eos;
106
+ if (!*eos) {
107
+ RETURN_IF_ERROR (get_next_block_async (state));
108
+ }
109
+ return Status::OK ();
110
+ }
111
+
112
+ Status SchemaScanner::get_next_block_async (RuntimeState* state) {
113
+ _dependency->block ();
114
+ auto task_ctx = state->get_task_execution_context ();
115
+ RETURN_IF_ERROR (ExecEnv::GetInstance ()->fragment_mgr ()->get_thread_pool ()->submit_func (
116
+ [this , task_ctx, state]() {
117
+ DCHECK (_async_thread_running == false );
118
+ auto task_lock = task_ctx.lock ();
119
+ if (task_lock == nullptr ) {
120
+ _scanner_status.update (Status::InternalError (" Task context not exists!" ));
121
+ return ;
122
+ }
123
+ SCOPED_ATTACH_TASK (state);
124
+ _dependency->block ();
125
+ _async_thread_running = true ;
126
+ _finish_dependency->block ();
127
+ if (!_opened) {
128
+ _data_block = vectorized::Block::create_unique ();
129
+ _init_block (_data_block.get ());
130
+ _scanner_status.update (start (state));
131
+ _opened = true ;
132
+ }
133
+ bool eos = false ;
134
+ _scanner_status.update (get_next_block_internal (_data_block.get (), &eos));
135
+ _eos = eos;
136
+ _async_thread_running = false ;
137
+ _dependency->set_ready ();
138
+ if (eos) {
139
+ _finish_dependency->set_ready ();
140
+ }
141
+ }));
142
+ return Status::OK ();
143
+ }
144
+
145
+ Status SchemaScanner::get_next_block_internal (vectorized::Block* block, bool * eos) {
89
146
if (!_is_init) {
90
147
return Status::InternalError (" used before initialized." );
91
148
}
@@ -176,6 +233,16 @@ std::unique_ptr<SchemaScanner> SchemaScanner::create(TSchemaTableType::type type
176
233
}
177
234
}
178
235
236
+ void SchemaScanner::_init_block (vectorized::Block* src_block) {
237
+ const std::vector<SchemaScanner::ColumnDesc>& columns_desc (get_column_desc ());
238
+ for (int i = 0 ; i < columns_desc.size (); ++i) {
239
+ TypeDescriptor descriptor (columns_desc[i].type );
240
+ auto data_type = vectorized::DataTypeFactory::instance ().create_data_type (descriptor, true );
241
+ src_block->insert (vectorized::ColumnWithTypeAndName (data_type->create_column (), data_type,
242
+ columns_desc[i].name ));
243
+ }
244
+ }
245
+
179
246
Status SchemaScanner::fill_dest_column_for_range (vectorized::Block* block, size_t pos,
180
247
const std::vector<void *>& datas) {
181
248
const ColumnDesc& col_desc = _columns[pos];
0 commit comments