@@ -17,7 +17,6 @@ use std::sync::Arc;
17
17
use databend_common_catalog:: lock:: LockTableOption ;
18
18
use databend_common_catalog:: plan:: StageTableInfo ;
19
19
use databend_common_catalog:: table:: TableExt ;
20
- use databend_common_exception:: ErrorCode ;
21
20
use databend_common_exception:: Result ;
22
21
use databend_common_expression:: types:: Int32Type ;
23
22
use databend_common_expression:: types:: StringType ;
@@ -28,8 +27,7 @@ use databend_common_sql::executor::physical_plans::MutationKind;
28
27
use databend_common_sql:: executor:: PhysicalPlanBuilder ;
29
28
use databend_common_sql:: optimizer:: SExpr ;
30
29
use databend_common_sql:: plans:: AppendType ;
31
- use databend_common_sql:: plans:: RelOperator ;
32
- use log:: debug;
30
+ use databend_common_sql:: IndexType ;
33
31
use log:: info;
34
32
35
33
use crate :: interpreters:: common:: check_deduplicate_label;
@@ -41,17 +39,18 @@ use crate::pipelines::PipelineBuilder;
41
39
use crate :: schedulers:: build_query_pipeline_without_render_result_set;
42
40
use crate :: sessions:: QueryContext ;
43
41
use crate :: sessions:: TableContext ;
44
- use crate :: sql:: plans:: Append ;
45
42
use crate :: sql:: MetadataRef ;
46
43
use crate :: stream:: DataBlockStream ;
47
44
48
45
pub struct AppendInterpreter {
49
46
ctx : Arc < QueryContext > ,
50
47
s_expr : SExpr ,
51
48
metadata : MetadataRef ,
49
+ target_table_index : IndexType ,
52
50
stage_table_info : Option < Box < StageTableInfo > > ,
53
51
overwrite : bool ,
54
- col_type_modified : bool ,
52
+ forbid_occ_retry : bool ,
53
+ append_type : AppendType ,
55
54
}
56
55
57
56
#[ async_trait:: async_trait]
@@ -67,44 +66,20 @@ impl Interpreter for AppendInterpreter {
67
66
#[ fastrace:: trace]
68
67
#[ async_backtrace:: framed]
69
68
async fn execute2 ( & self ) -> Result < PipelineBuildResult > {
70
- debug ! ( "ctx.id" = self . ctx. get_id( ) . as_str( ) ; "append_interpreter_execute" ) ;
71
69
if check_deduplicate_label ( self . ctx . clone ( ) ) . await ? {
72
70
return Ok ( PipelineBuildResult :: create ( ) ) ;
73
71
}
74
-
75
- let append: Append = match & self . s_expr . plan ( ) {
76
- RelOperator :: Append ( append) => append. clone ( ) ,
77
- RelOperator :: Exchange ( _) => self . s_expr . child ( 0 ) . unwrap ( ) . plan ( ) . clone ( ) . try_into ( ) ?,
78
- plan => {
79
- return Err ( ErrorCode :: Internal ( format ! (
80
- "AppendInterpreter: unexpected plan type: {:?}" ,
81
- plan
82
- ) ) ) ;
83
- }
84
- } ;
85
72
let ( target_table, catalog, database, table) = {
86
73
let metadata = self . metadata . read ( ) ;
87
- let t = metadata. table ( append . table_index ) ;
74
+ let t = metadata. table ( self . target_table_index ) ;
88
75
(
89
76
t. table ( ) ,
90
77
t. catalog ( ) . to_string ( ) ,
91
78
t. database ( ) . to_string ( ) ,
92
79
t. name ( ) . to_string ( ) ,
93
80
)
94
81
} ;
95
-
96
82
target_table. check_mutable ( ) ?;
97
- if append
98
- . project_columns
99
- . as_ref ( )
100
- . is_some_and ( |p| p. len ( ) != append. required_source_schema . num_fields ( ) )
101
- {
102
- return Err ( ErrorCode :: BadArguments ( format ! (
103
- "Fields in select statement is not equal with expected, select fields: {}, insert fields: {}" ,
104
- append. project_columns. as_ref( ) . unwrap( ) . len( ) ,
105
- append. required_source_schema. num_fields( ) ,
106
- ) ) ) ;
107
- }
108
83
109
84
// 1. build source and append pipeline
110
85
let mut build_res = {
@@ -137,7 +112,7 @@ impl Interpreter for AppendInterpreter {
137
112
copied_files_meta_req,
138
113
update_stream_meta,
139
114
self . overwrite ,
140
- self . col_type_modified ,
115
+ self . forbid_occ_retry ,
141
116
unsafe { self . ctx . get_settings ( ) . get_deduplicate_label ( ) ? } ,
142
117
) ?;
143
118
@@ -184,12 +159,7 @@ impl Interpreter for AppendInterpreter {
184
159
}
185
160
186
161
fn inject_result ( & self ) -> Result < SendableDataBlockStream > {
187
- let append: Append = match & self . s_expr . plan ( ) {
188
- RelOperator :: Append ( append) => append. clone ( ) ,
189
- RelOperator :: Exchange ( _) => self . s_expr . child ( 0 ) . unwrap ( ) . plan ( ) . clone ( ) . try_into ( ) ?,
190
- _ => unreachable ! ( ) ,
191
- } ;
192
- match & append. append_type {
162
+ match & self . append_type {
193
163
AppendType :: CopyInto => {
194
164
let blocks = self . get_copy_into_table_result ( ) ?;
195
165
Ok ( Box :: pin ( DataBlockStream :: create ( None , blocks) ) )
@@ -206,15 +176,19 @@ impl AppendInterpreter {
206
176
metadata : MetadataRef ,
207
177
stage_table_info : Option < Box < StageTableInfo > > ,
208
178
overwrite : bool ,
209
- col_type_modified : bool ,
179
+ forbid_occ_retry : bool ,
180
+ append_type : AppendType ,
181
+ table_index : IndexType ,
210
182
) -> Result < Self > {
211
183
Ok ( AppendInterpreter {
212
184
ctx,
213
185
s_expr,
214
186
metadata,
215
187
stage_table_info,
216
188
overwrite,
217
- col_type_modified,
189
+ forbid_occ_retry,
190
+ append_type,
191
+ target_table_index : table_index,
218
192
} )
219
193
}
220
194
0 commit comments