@@ -20,7 +20,6 @@ use common_base::base::ProgressValues;
2020use common_catalog:: table_context:: TableContext ;
2121use common_datablocks:: DataBlock ;
2222use common_datavalues:: ColumnRef ;
23- use common_datavalues:: DataSchemaRef ;
2423use common_datavalues:: DataSchemaRefExt ;
2524use common_exception:: ErrorCode ;
2625use common_exception:: Result ;
@@ -84,8 +83,6 @@ impl FuseTable {
8483 ) -> Result < ( ) > {
8584 let table_schema = self . table_info . schema ( ) ;
8685 let projection = self . projection_of_push_downs ( & plan. push_downs ) ;
87- let output_schema = projection. project_schema ( & table_schema) ;
88- let output_schema = Arc :: new ( output_schema) ;
8986 let output_reader = self . create_block_reader ( & ctx, projection) ?; // for deserialize output blocks
9087
9188 let ( output_reader, prewhere_reader, prewhere_filter, remain_reader) =
@@ -139,7 +136,6 @@ impl FuseTable {
139136 FuseTableSource :: create (
140137 ctx. clone ( ) ,
141138 output,
142- output_schema. clone ( ) ,
143139 output_reader. clone ( ) ,
144140 prewhere_reader. clone ( ) ,
145141 prewhere_filter. clone ( ) ,
@@ -174,7 +170,6 @@ struct FuseTableSource {
174170 ctx : Arc < dyn TableContext > ,
175171 scan_progress : Arc < Progress > ,
176172 output : Arc < OutputPort > ,
177- output_schema : DataSchemaRef ,
178173 output_reader : Arc < BlockReader > ,
179174
180175 prewhere_reader : Arc < BlockReader > ,
@@ -186,7 +181,6 @@ impl FuseTableSource {
186181 pub fn create (
187182 ctx : Arc < dyn TableContext > ,
188183 output : Arc < OutputPort > ,
189- output_schema : DataSchemaRef ,
190184 output_reader : Arc < BlockReader > ,
191185 prewhere_reader : Arc < BlockReader > ,
192186 prewhere_filter : Arc < Option < ExpressionExecutor > > ,
@@ -200,7 +194,6 @@ impl FuseTableSource {
200194 output,
201195 scan_progress,
202196 state : State :: Finish ,
203- output_schema,
204197 output_reader,
205198 prewhere_reader,
206199 prewhere_filter,
@@ -211,7 +204,6 @@ impl FuseTableSource {
211204 output,
212205 scan_progress,
213206 state : State :: ReadDataPrewhere ( partitions. remove ( 0 ) ) ,
214- output_schema,
215207 output_reader,
216208 prewhere_reader,
217209 prewhere_filter,
@@ -222,7 +214,8 @@ impl FuseTableSource {
222214
223215 fn generate_one_block ( & mut self , block : DataBlock ) -> Result < ( ) > {
224216 let mut partitions = self . ctx . try_get_partitions ( 1 ) ?;
225-
217+ // resort and prune columns
218+ let block = block. resort ( self . output_reader . schema ( ) ) ?;
226219 self . state = match partitions. is_empty ( ) {
227220 true => State :: Generated ( None , block) ,
228221 false => State :: Generated ( Some ( partitions. remove ( 0 ) ) , block) ,
@@ -235,11 +228,11 @@ impl FuseTableSource {
235228 self . state = match partitions. is_empty ( ) {
236229 true => State :: Generated (
237230 None ,
238- DataBlock :: empty_with_schema ( self . output_schema . clone ( ) ) ,
231+ DataBlock :: empty_with_schema ( self . output_reader . schema ( ) ) ,
239232 ) ,
240233 false => State :: Generated (
241234 Some ( partitions. remove ( 0 ) ) ,
242- DataBlock :: empty_with_schema ( self . output_schema . clone ( ) ) ,
235+ DataBlock :: empty_with_schema ( self . output_reader . schema ( ) ) ,
243236 ) ,
244237 } ;
245238 Ok ( ( ) )
@@ -312,7 +305,7 @@ impl Processor for FuseTableSource {
312305 prewhere_blocks =
313306 prewhere_blocks. add_column ( col. clone ( ) , field. clone ( ) ) ?;
314307 }
315- prewhere_blocks. resort ( self . output_reader . schema ( ) ) ?
308+ prewhere_blocks
316309 } else {
317310 return Err ( ErrorCode :: LogicalError ( "It's a bug. Need remain reader" ) ) ;
318311 } ;
0 commit comments