@@ -16,10 +16,8 @@ use std::collections::VecDeque;
16
16
use std:: sync:: Arc ;
17
17
18
18
use common_catalog:: table:: Table ;
19
- use common_datavalues:: DataType ;
20
19
use common_exception:: ErrorCode ;
21
20
use common_exception:: Result ;
22
- use common_functions:: scalars:: CastFunction ;
23
21
use common_streams:: DataBlockStream ;
24
22
use common_streams:: SendableDataBlockStream ;
25
23
use futures_util:: StreamExt ;
@@ -29,15 +27,12 @@ use super::commit2table;
29
27
use super :: interpreter_common:: append2table;
30
28
use super :: plan_schedulers:: build_schedule_pipepline;
31
29
use super :: ProcessorExecutorStream ;
32
- use crate :: clusters:: ClusterHelper ;
33
30
use crate :: interpreters:: Interpreter ;
34
31
use crate :: interpreters:: InterpreterPtr ;
35
- use crate :: interpreters:: SelectInterpreterV2 ;
36
32
use crate :: pipelines:: executor:: ExecutorSettings ;
37
33
use crate :: pipelines:: executor:: PipelinePullingExecutor ;
38
34
use crate :: pipelines:: processors:: port:: OutputPort ;
39
35
use crate :: pipelines:: processors:: BlocksSource ;
40
- use crate :: pipelines:: processors:: TransformCastSchema ;
41
36
use crate :: pipelines:: Pipeline ;
42
37
use crate :: pipelines:: PipelineBuildResult ;
43
38
use crate :: pipelines:: SourcePipeBuilder ;
@@ -46,6 +41,7 @@ use crate::sessions::TableContext;
46
41
use crate :: sql:: executor:: DistributedInsertSelect ;
47
42
use crate :: sql:: executor:: PhysicalPlan ;
48
43
use crate :: sql:: executor:: PhysicalPlanBuilder ;
44
+ use crate :: sql:: executor:: PipelineBuilder ;
49
45
use crate :: sql:: plans:: Insert ;
50
46
use crate :: sql:: plans:: InsertInputSource ;
51
47
use crate :: sql:: plans:: Plan ;
@@ -111,64 +107,7 @@ impl InsertInterpreterV2 {
111
107
) ;
112
108
}
113
109
InsertInputSource :: SelectPlan ( plan) => {
114
- if !self . ctx . get_cluster ( ) . is_empty ( ) {
115
- // distributed insert select
116
- if let Some ( stream) = self
117
- . schedule_insert_select ( plan, self . plan . catalog . clone ( ) , table. clone ( ) )
118
- . await ?
119
- {
120
- return Ok ( stream) ;
121
- }
122
- // else the plan cannot be executed in cluster mode, fallback to standalone mode
123
- }
124
-
125
- let select_interpreter = match & * * plan {
126
- Plan :: Query {
127
- s_expr,
128
- metadata,
129
- bind_context,
130
- ..
131
- } => SelectInterpreterV2 :: try_create (
132
- self . ctx . clone ( ) ,
133
- * bind_context. clone ( ) ,
134
- * s_expr. clone ( ) ,
135
- metadata. clone ( ) ,
136
- ) ,
137
- _ => unreachable ! ( ) ,
138
- } ;
139
-
140
- build_res = select_interpreter?. create_new_pipeline ( ) . await ?;
141
-
142
- if self . check_schema_cast ( plan) ? {
143
- let mut functions = Vec :: with_capacity ( self . plan . schema ( ) . fields ( ) . len ( ) ) ;
144
-
145
- for ( target_field, original_field) in self
146
- . plan
147
- . schema ( )
148
- . fields ( )
149
- . iter ( )
150
- . zip ( plan. schema ( ) . fields ( ) . iter ( ) )
151
- {
152
- let target_type_name = target_field. data_type ( ) . name ( ) ;
153
- let from_type = original_field. data_type ( ) . clone ( ) ;
154
- let cast_function =
155
- CastFunction :: create ( "cast" , & target_type_name, from_type) ?;
156
- functions. push ( cast_function) ;
157
- }
158
-
159
- let func_ctx = self . ctx . try_get_function_context ( ) ?;
160
- build_res. main_pipeline . add_transform (
161
- |transform_input_port, transform_output_port| {
162
- TransformCastSchema :: try_create (
163
- transform_input_port,
164
- transform_output_port,
165
- self . plan . schema ( ) ,
166
- functions. clone ( ) ,
167
- func_ctx. clone ( ) ,
168
- )
169
- } ,
170
- ) ?;
171
- }
110
+ return self . schedule_insert_select ( plan, table. clone ( ) ) . await ;
172
111
}
173
112
} ;
174
113
}
@@ -202,9 +141,8 @@ impl InsertInterpreterV2 {
202
141
async fn schedule_insert_select (
203
142
& self ,
204
143
plan : & Plan ,
205
- catalog : String ,
206
144
table : Arc < dyn Table > ,
207
- ) -> Result < Option < SendableDataBlockStream > > {
145
+ ) -> Result < SendableDataBlockStream > {
208
146
// select_plan is already distributed optimized
209
147
let ( mut select_plan, select_column_bindings) = match plan {
210
148
Plan :: Query {
@@ -219,11 +157,9 @@ impl InsertInterpreterV2 {
219
157
_ => unreachable ! ( ) ,
220
158
} ;
221
159
222
- if !select_plan. is_distributed_plan ( ) {
223
- return Ok ( None ) ;
224
- }
225
-
226
160
table. get_table_info ( ) ;
161
+ let catalog = self . plan . catalog . clone ( ) ;
162
+ let is_distributed_plan = select_plan. is_distributed_plan ( ) ;
227
163
228
164
let insert_select_plan = match select_plan {
229
165
PhysicalPlan :: Exchange ( ref mut exchange) => {
@@ -256,7 +192,12 @@ impl InsertInterpreterV2 {
256
192
}
257
193
} ;
258
194
259
- let mut build_res = build_schedule_pipepline ( self . ctx . clone ( ) , & insert_select_plan) . await ?;
195
+ let mut build_res = if !is_distributed_plan {
196
+ let builder = PipelineBuilder :: create ( self . ctx . clone ( ) ) ;
197
+ builder. finalize ( & insert_select_plan) ?
198
+ } else {
199
+ build_schedule_pipepline ( self . ctx . clone ( ) , & insert_select_plan) . await ?
200
+ } ;
260
201
261
202
let settings = self . ctx . get_settings ( ) ;
262
203
let query_need_abort = self . ctx . query_need_abort ( ) ;
@@ -277,11 +218,11 @@ impl InsertInterpreterV2 {
277
218
278
219
commit2table ( self . ctx . clone ( ) , table. clone ( ) , self . plan . overwrite ) . await ?;
279
220
280
- Ok ( Some ( Box :: pin ( DataBlockStream :: create (
221
+ Ok ( Box :: pin ( DataBlockStream :: create (
281
222
self . plan . schema ( ) ,
282
223
None ,
283
224
vec ! [ ] ,
284
- ) ) ) )
225
+ ) ) )
285
226
}
286
227
}
287
228
0 commit comments