@@ -17,7 +17,6 @@ use std::sync::Arc;
1717use databend_common_catalog:: lock:: LockTableOption ;
1818use databend_common_catalog:: plan:: StageTableInfo ;
1919use databend_common_catalog:: table:: TableExt ;
20- use databend_common_exception:: ErrorCode ;
2120use databend_common_exception:: Result ;
2221use databend_common_expression:: types:: Int32Type ;
2322use databend_common_expression:: types:: StringType ;
@@ -28,8 +27,7 @@ use databend_common_sql::executor::physical_plans::MutationKind;
2827use databend_common_sql:: executor:: PhysicalPlanBuilder ;
2928use databend_common_sql:: optimizer:: SExpr ;
3029use databend_common_sql:: plans:: AppendType ;
31- use databend_common_sql:: plans:: RelOperator ;
32- use log:: debug;
30+ use databend_common_sql:: IndexType ;
3331use log:: info;
3432
3533use crate :: interpreters:: common:: check_deduplicate_label;
@@ -41,17 +39,18 @@ use crate::pipelines::PipelineBuilder;
4139use crate :: schedulers:: build_query_pipeline_without_render_result_set;
4240use crate :: sessions:: QueryContext ;
4341use crate :: sessions:: TableContext ;
44- use crate :: sql:: plans:: Append ;
4542use crate :: sql:: MetadataRef ;
4643use crate :: stream:: DataBlockStream ;
4744
4845pub struct AppendInterpreter {
4946 ctx : Arc < QueryContext > ,
5047 s_expr : SExpr ,
5148 metadata : MetadataRef ,
49+ target_table_index : IndexType ,
5250 stage_table_info : Option < Box < StageTableInfo > > ,
5351 overwrite : bool ,
54- col_type_modified : bool ,
52+ forbid_occ_retry : bool ,
53+ append_type : AppendType ,
5554}
5655
5756#[ async_trait:: async_trait]
@@ -67,44 +66,20 @@ impl Interpreter for AppendInterpreter {
6766 #[ fastrace:: trace]
6867 #[ async_backtrace:: framed]
6968 async fn execute2 ( & self ) -> Result < PipelineBuildResult > {
70- debug ! ( "ctx.id" = self . ctx. get_id( ) . as_str( ) ; "append_interpreter_execute" ) ;
7169 if check_deduplicate_label ( self . ctx . clone ( ) ) . await ? {
7270 return Ok ( PipelineBuildResult :: create ( ) ) ;
7371 }
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- } ;
8572 let ( target_table, catalog, database, table) = {
8673 let metadata = self . metadata . read ( ) ;
87- let t = metadata. table ( append . table_index ) ;
74+ let t = metadata. table ( self . target_table_index ) ;
8875 (
8976 t. table ( ) ,
9077 t. catalog ( ) . to_string ( ) ,
9178 t. database ( ) . to_string ( ) ,
9279 t. name ( ) . to_string ( ) ,
9380 )
9481 } ;
95-
9682 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- }
10883
10984 // 1. build source and append pipeline
11085 let mut build_res = {
@@ -137,7 +112,7 @@ impl Interpreter for AppendInterpreter {
137112 copied_files_meta_req,
138113 update_stream_meta,
139114 self . overwrite ,
140- self . col_type_modified ,
115+ self . forbid_occ_retry ,
141116 unsafe { self . ctx . get_settings ( ) . get_deduplicate_label ( ) ? } ,
142117 ) ?;
143118
@@ -184,12 +159,7 @@ impl Interpreter for AppendInterpreter {
184159 }
185160
186161 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 {
193163 AppendType :: CopyInto => {
194164 let blocks = self . get_copy_into_table_result ( ) ?;
195165 Ok ( Box :: pin ( DataBlockStream :: create ( None , blocks) ) )
@@ -206,15 +176,19 @@ impl AppendInterpreter {
206176 metadata : MetadataRef ,
207177 stage_table_info : Option < Box < StageTableInfo > > ,
208178 overwrite : bool ,
209- col_type_modified : bool ,
179+ forbid_occ_retry : bool ,
180+ append_type : AppendType ,
181+ table_index : IndexType ,
210182 ) -> Result < Self > {
211183 Ok ( AppendInterpreter {
212184 ctx,
213185 s_expr,
214186 metadata,
215187 stage_table_info,
216188 overwrite,
217- col_type_modified,
189+ forbid_occ_retry,
190+ append_type,
191+ target_table_index : table_index,
218192 } )
219193 }
220194
0 commit comments