1616// under the License.
1717
1818use crate :: physical_exec:: OrcOpener ;
19- use datafusion:: common:: Statistics ;
19+ use datafusion:: common:: DataFusionError ;
2020use datafusion:: datasource:: physical_plan:: { FileOpener , FileScanConfig , FileSource } ;
21+ use datafusion:: datasource:: table_schema:: TableSchema ;
2122use datafusion:: physical_plan:: metrics:: ExecutionPlanMetricsSet ;
22- use datafusion_datasource :: TableSchema ;
23+ use datafusion :: physical_plan :: projection :: ProjectionExprs ;
2324use object_store:: ObjectStore ;
2425use std:: any:: Any ;
2526use std:: sync:: Arc ;
2627
2728#[ derive( Debug , Clone ) ]
2829pub struct OrcSource {
2930 metrics : ExecutionPlanMetricsSet ,
30- statistics : Statistics ,
3131 batch_size : usize ,
32+ table_schema : TableSchema ,
33+ projection : ProjectionExprs ,
3234}
3335
34- impl Default for OrcSource {
35- fn default ( ) -> Self {
36+ impl OrcSource {
37+ pub fn new ( table_schema : TableSchema ) -> Self {
38+ let table_schema_ref = table_schema. table_schema ( ) ;
39+ let projection = ProjectionExprs :: from_indices (
40+ & ( 0 ..table_schema_ref. fields ( ) . len ( ) ) . collect :: < Vec < _ > > ( ) ,
41+ table_schema_ref,
42+ ) ;
3643 Self {
3744 metrics : ExecutionPlanMetricsSet :: default ( ) ,
38- statistics : Statistics :: default ( ) ,
3945 batch_size : 1024 ,
46+ table_schema,
47+ projection,
4048 }
4149 }
4250}
@@ -47,45 +55,49 @@ impl FileSource for OrcSource {
4755 object_store : Arc < dyn ObjectStore > ,
4856 config : & FileScanConfig ,
4957 _partition : usize ,
50- ) -> Arc < dyn FileOpener > {
51- Arc :: new ( OrcOpener :: new ( object_store, config, self . batch_size ) )
58+ ) -> Result < Arc < dyn FileOpener > , DataFusionError > {
59+ OrcOpener :: try_new (
60+ object_store,
61+ self . table_schema . table_schema ( ) . clone ( ) ,
62+ config. batch_size . unwrap_or ( self . batch_size ) ,
63+ self . projection . clone ( ) ,
64+ )
65+ . map ( |f| Arc :: new ( f) as Arc < dyn FileOpener > )
5266 }
5367
5468 fn as_any ( & self ) -> & dyn Any {
5569 self
5670 }
5771
72+ fn table_schema ( & self ) -> & TableSchema {
73+ & self . table_schema
74+ }
75+
5876 fn with_batch_size ( & self , batch_size : usize ) -> Arc < dyn FileSource > {
5977 Arc :: new ( Self {
6078 batch_size,
6179 ..self . clone ( )
6280 } )
6381 }
6482
65- fn with_schema ( & self , _schema : TableSchema ) -> Arc < dyn FileSource > {
66- Arc :: new ( self . clone ( ) )
67- }
68-
69- fn with_projection ( & self , _config : & FileScanConfig ) -> Arc < dyn FileSource > {
70- Arc :: new ( self . clone ( ) )
71- }
72-
73- fn with_statistics ( & self , statistics : Statistics ) -> Arc < dyn FileSource > {
74- Arc :: new ( Self {
75- statistics,
76- ..self . clone ( )
77- } )
83+ fn projection ( & self ) -> Option < & ProjectionExprs > {
84+ Some ( & self . projection )
7885 }
7986
8087 fn metrics ( & self ) -> & ExecutionPlanMetricsSet {
8188 & self . metrics
8289 }
8390
84- fn statistics ( & self ) -> datafusion:: common:: Result < Statistics > {
85- Ok ( self . statistics . clone ( ) )
86- }
87-
8891 fn file_type ( & self ) -> & str {
8992 "orc"
9093 }
94+
95+ fn try_pushdown_projection (
96+ & self ,
97+ projection : & ProjectionExprs ,
98+ ) -> Result < Option < Arc < dyn FileSource > > , DataFusionError > {
99+ let mut source = self . clone ( ) ;
100+ source. projection = self . projection . try_merge ( projection) ?;
101+ Ok ( Some ( Arc :: new ( source) ) )
102+ }
91103}
0 commit comments