@@ -16,12 +16,12 @@ use std::collections::BTreeMap;
1616use std:: sync:: Arc ;
1717
1818use common_datavalues:: DataField ;
19+ use common_datavalues:: DataSchema ;
1920use common_exception:: Result ;
2021use common_legacy_planners:: Extras ;
2122use common_legacy_planners:: Projection ;
2223use common_legacy_planners:: ReadDataSourcePlan ;
2324use common_legacy_planners:: SourceInfo ;
24- use common_meta_app:: schema:: TableInfo ;
2525
2626use crate :: sessions:: QueryContext ;
2727use crate :: storages:: Table ;
@@ -55,16 +55,21 @@ impl ToReadDataSourcePlan for dyn Table {
5555 push_downs : Option < Extras > ,
5656 ) -> Result < ReadDataSourcePlan > {
5757 let ( statistics, parts) = self . read_partitions ( ctx, push_downs. clone ( ) ) . await ?;
58+
5859 let table_info = self . get_table_info ( ) ;
60+ let table_meta = & table_info. meta ;
5961 let description = statistics. get_description ( table_info) ;
6062
6163 let scan_fields = match ( self . benefit_column_prune ( ) , & push_downs) {
6264 ( true , Some ( push_downs) ) => match & push_downs. prewhere {
63- Some ( prewhere) => {
64- extract_scan_fields_from_projection ( table_info, & prewhere. output_columns )
65- }
65+ Some ( prewhere) => extract_scan_fields_from_projection (
66+ & table_meta. schema ,
67+ & prewhere. output_columns ,
68+ ) ,
6669 _ => match & push_downs. projection {
67- Some ( projection) => extract_scan_fields_from_projection ( table_info, projection) ,
70+ Some ( projection) => {
71+ extract_scan_fields_from_projection ( & table_meta. schema , projection)
72+ }
6873 _ => None ,
6974 } ,
7075 } ,
@@ -87,15 +92,13 @@ impl ToReadDataSourcePlan for dyn Table {
8792}
8893
8994fn extract_scan_fields_from_projection (
90- table_info : & TableInfo ,
95+ schema : & DataSchema ,
9196 projection : & Projection ,
9297) -> Option < BTreeMap < usize , DataField > > {
9398 match projection {
9499 Projection :: Columns ( ref indices) => {
95- if indices. len ( ) < table_info. schema ( ) . fields ( ) . len ( ) {
96- let fields = indices
97- . iter ( )
98- . map ( |i| table_info. schema ( ) . field ( * i) . clone ( ) ) ;
100+ if indices. len ( ) < schema. fields ( ) . len ( ) {
101+ let fields = indices. iter ( ) . map ( |i| schema. field ( * i) . clone ( ) ) ;
99102
100103 Some ( ( indices. iter ( ) . cloned ( ) . zip ( fields) ) . collect :: < BTreeMap < _ , _ > > ( ) )
101104 } else {
@@ -104,7 +107,7 @@ fn extract_scan_fields_from_projection(
104107 }
105108 Projection :: InnerColumns ( ref path_indices) => {
106109 let column_ids: Vec < usize > = path_indices. keys ( ) . cloned ( ) . collect ( ) ;
107- let new_schema = table_info . schema ( ) . inner_project ( path_indices) ;
110+ let new_schema = schema. inner_project ( path_indices) ;
108111 Some (
109112 ( column_ids. iter ( ) . cloned ( ) . zip ( new_schema. fields ( ) . clone ( ) ) )
110113 . collect :: < BTreeMap < _ , _ > > ( ) ,
0 commit comments