@@ -16,12 +16,12 @@ use std::collections::BTreeMap;
16
16
use std:: sync:: Arc ;
17
17
18
18
use common_datavalues:: DataField ;
19
+ use common_datavalues:: DataSchema ;
19
20
use common_exception:: Result ;
20
21
use common_legacy_planners:: Extras ;
21
22
use common_legacy_planners:: Projection ;
22
23
use common_legacy_planners:: ReadDataSourcePlan ;
23
24
use common_legacy_planners:: SourceInfo ;
24
- use common_meta_app:: schema:: TableInfo ;
25
25
26
26
use crate :: sessions:: QueryContext ;
27
27
use crate :: storages:: Table ;
@@ -55,16 +55,21 @@ impl ToReadDataSourcePlan for dyn Table {
55
55
push_downs : Option < Extras > ,
56
56
) -> Result < ReadDataSourcePlan > {
57
57
let ( statistics, parts) = self . read_partitions ( ctx, push_downs. clone ( ) ) . await ?;
58
+
58
59
let table_info = self . get_table_info ( ) ;
60
+ let table_meta = & table_info. meta ;
59
61
let description = statistics. get_description ( table_info) ;
60
62
61
63
let scan_fields = match ( self . benefit_column_prune ( ) , & push_downs) {
62
64
( 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
+ ) ,
66
69
_ => 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
+ }
68
73
_ => None ,
69
74
} ,
70
75
} ,
@@ -87,15 +92,13 @@ impl ToReadDataSourcePlan for dyn Table {
87
92
}
88
93
89
94
fn extract_scan_fields_from_projection (
90
- table_info : & TableInfo ,
95
+ schema : & DataSchema ,
91
96
projection : & Projection ,
92
97
) -> Option < BTreeMap < usize , DataField > > {
93
98
match projection {
94
99
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 ( ) ) ;
99
102
100
103
Some ( ( indices. iter ( ) . cloned ( ) . zip ( fields) ) . collect :: < BTreeMap < _ , _ > > ( ) )
101
104
} else {
@@ -104,7 +107,7 @@ fn extract_scan_fields_from_projection(
104
107
}
105
108
Projection :: InnerColumns ( ref path_indices) => {
106
109
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) ;
108
111
Some (
109
112
( column_ids. iter ( ) . cloned ( ) . zip ( new_schema. fields ( ) . clone ( ) ) )
110
113
. collect :: < BTreeMap < _ , _ > > ( ) ,
0 commit comments