@@ -35,11 +35,12 @@ use datafusion_datasource::schema_adapter::{
3535 DefaultSchemaAdapterFactory , SchemaAdapterFactory ,
3636} ;
3737
38- use arrow:: datatypes:: { SchemaRef , TimeUnit } ;
38+ use arrow:: datatypes:: TimeUnit ;
3939use datafusion_common:: config:: TableParquetOptions ;
4040use datafusion_common:: { DataFusionError , Statistics } ;
4141use datafusion_datasource:: file:: FileSource ;
4242use datafusion_datasource:: file_scan_config:: FileScanConfig ;
43+ use datafusion_datasource:: TableSchema ;
4344use datafusion_physical_expr:: conjunction;
4445use datafusion_physical_expr_adapter:: DefaultPhysicalExprAdapterFactory ;
4546use datafusion_physical_expr_common:: physical_expr:: fmt_sql;
@@ -274,7 +275,7 @@ pub struct ParquetSource {
274275 /// The schema of the file.
275276 /// In particular, this is the schema of the table without partition columns,
276277 /// *not* the physical schema of the file.
277- pub ( crate ) file_schema : Option < SchemaRef > ,
278+ pub ( crate ) table_schema : Option < TableSchema > ,
278279 /// Optional predicate for row filtering during parquet scan
279280 pub ( crate ) predicate : Option < Arc < dyn PhysicalExpr > > ,
280281 /// Optional user defined parquet file reader factory
@@ -599,9 +600,9 @@ impl FileSource for ParquetSource {
599600 Arc :: new ( conf)
600601 }
601602
602- fn with_schema ( & self , schema : SchemaRef ) -> Arc < dyn FileSource > {
603+ fn with_schema ( & self , schema : TableSchema ) -> Arc < dyn FileSource > {
603604 Arc :: new ( Self {
604- file_schema : Some ( schema) ,
605+ table_schema : Some ( schema) ,
605606 ..self . clone ( )
606607 } )
607608 }
@@ -659,9 +660,10 @@ impl FileSource for ParquetSource {
659660 // the actual predicates are built in reference to the physical schema of
660661 // each file, which we do not have at this point and hence cannot use.
661662 // Instead we use the logical schema of the file (the table schema without partition columns).
662- if let ( Some ( file_schema) , Some ( predicate) ) =
663- ( & self . file_schema , & self . predicate )
664- {
663+ if let ( Some ( file_schema) , Some ( predicate) ) = (
664+ & self . table_schema . as_ref ( ) . map ( |ts| ts. file_schema ( ) ) ,
665+ & self . predicate ,
666+ ) {
665667 let predicate_creation_errors = Count :: new ( ) ;
666668 if let ( Some ( pruning_predicate) , _) = build_pruning_predicates (
667669 Some ( predicate) ,
@@ -698,7 +700,12 @@ impl FileSource for ParquetSource {
698700 filters : Vec < Arc < dyn PhysicalExpr > > ,
699701 config : & ConfigOptions ,
700702 ) -> datafusion_common:: Result < FilterPushdownPropagation < Arc < dyn FileSource > > > {
701- let Some ( file_schema) = self . file_schema . clone ( ) else {
703+ let Some ( table_schema) = self
704+ . table_schema
705+ . as_ref ( )
706+ . map ( |ts| ts. table_schema ( ) )
707+ . cloned ( )
708+ else {
702709 return Ok ( FilterPushdownPropagation :: with_parent_pushdown_result (
703710 vec ! [ PushedDown :: No ; filters. len( ) ] ,
704711 ) ) ;
@@ -718,7 +725,7 @@ impl FileSource for ParquetSource {
718725 let filters: Vec < PushedDownPredicate > = filters
719726 . into_iter ( )
720727 . map ( |filter| {
721- if can_expr_be_pushed_down_with_schemas ( & filter, & file_schema ) {
728+ if can_expr_be_pushed_down_with_schemas ( & filter, & table_schema ) {
722729 PushedDownPredicate :: supported ( filter)
723730 } else {
724731 PushedDownPredicate :: unsupported ( filter)
0 commit comments