@@ -56,7 +56,7 @@ use datafusion_datasource::{
5656 file:: FileSource ,
5757 file_groups:: FileGroup ,
5858 file_scan_config:: { FileScanConfig , FileScanConfigBuilder } ,
59- schema_adapter:: { DefaultSchemaAdapterFactory , SchemaAdapter , SchemaAdapterFactory } ,
59+ schema_adapter:: SchemaAdapterFactory ,
6060} ;
6161use datafusion_expr:: { dml:: InsertOp , Expr , SortExpr , TableProviderFilterPushDown , TableType } ;
6262use futures:: future:: err;
@@ -948,7 +948,7 @@ pub struct ListingTable {
948948 schema_source : SchemaSource ,
949949 options : ListingOptions ,
950950 definition : Option < String > ,
951- collected_statistics : FileStatisticsCache ,
951+ collected_statistics : Arc < dyn FileStatisticsCache > ,
952952 constraints : Constraints ,
953953 column_defaults : HashMap < String , Expr > ,
954954 /// Optional [`SchemaAdapterFactory`] for creating schema adapters
@@ -1020,7 +1020,7 @@ impl ListingTable {
10201020 /// multiple times in the same session.
10211021 ///
10221022 /// If `None`, creates a new [`DefaultFileStatisticsCache`] scoped to this query.
1023- pub fn with_cache ( mut self , cache : Option < FileStatisticsCache > ) -> Self {
1023+ pub fn with_cache ( mut self , cache : Option < Arc < dyn FileStatisticsCache > > ) -> Self {
10241024 self . collected_statistics =
10251025 cache. unwrap_or_else ( || Arc :: new ( DefaultFileStatisticsCache :: default ( ) ) ) ;
10261026 self
@@ -1085,20 +1085,17 @@ impl ListingTable {
10851085 }
10861086
10871087 /// Creates a schema adapter for mapping between file and table schemas
1088- ///
1089- /// Uses the configured schema adapter factory if available, otherwise falls back
1090- /// to the default implementation.
1091- fn create_schema_adapter ( & self ) -> Box < dyn SchemaAdapter > {
1092- let table_schema = self . schema ( ) ;
1093- match & self . schema_adapter_factory {
1094- Some ( factory) => factory. create_with_projected_schema ( Arc :: clone ( & table_schema) ) ,
1095- None => DefaultSchemaAdapterFactory :: from_schema ( Arc :: clone ( & table_schema) ) ,
1096- }
1097- }
1098-
10991088 /// Creates a file source and applies schema adapter factory if available
11001089 fn create_file_source_with_schema_adapter ( & self ) -> Result < Arc < dyn FileSource > > {
1101- let mut source = self . options . format . file_source ( ) ;
1090+ let table_schema = datafusion_datasource:: table_schema:: TableSchema :: new (
1091+ self . file_schema . clone ( ) ,
1092+ self . options
1093+ . table_partition_cols
1094+ . iter ( )
1095+ . map ( |( name, dt) | Arc :: new ( Field :: new ( name, dt. clone ( ) , false ) ) as _ )
1096+ . collect ( ) ,
1097+ ) ;
1098+ let mut source = self . options . format . file_source ( table_schema) ;
11021099 // Apply schema adapter to source if available
11031100 //
11041101 // The source will use this SchemaAdapter to adapt data batches as they flow up the plan.
@@ -1309,16 +1306,14 @@ impl TableProvider for ListingTable {
13091306 state,
13101307 FileScanConfigBuilder :: new (
13111308 object_store_url,
1312- Arc :: clone ( & self . file_schema ) ,
13131309 file_source,
13141310 )
13151311 . with_file_groups ( partitioned_file_lists)
13161312 . with_constraints ( self . constraints . clone ( ) )
13171313 . with_statistics ( statistics)
1318- . with_projection_indices ( projection. cloned ( ) )
1314+ . with_projection_indices ( projection. cloned ( ) ) ?
13191315 . with_limit ( limit)
13201316 . with_output_ordering ( output_ordering)
1321- . with_table_partition_cols ( table_partition_cols)
13221317 . with_expr_adapter ( self . expr_adapter_factory . clone ( ) )
13231318 . build ( ) ,
13241319 )
@@ -1469,17 +1464,22 @@ impl ListingTable {
14691464 inexact_stats,
14701465 ) ?;
14711466
1472- let schema_adapter = self . create_schema_adapter ( ) ;
1473- let ( schema_mapper, _) = schema_adapter. map_schema ( self . file_schema . as_ref ( ) ) ?;
1474-
1475- stats. column_statistics = schema_mapper. map_column_statistics ( & stats. column_statistics ) ?;
1476- file_groups. iter_mut ( ) . try_for_each ( |file_group| {
1477- if let Some ( stat) = file_group. statistics_mut ( ) {
1478- stat. column_statistics =
1479- schema_mapper. map_column_statistics ( & stat. column_statistics ) ?;
1480- }
1481- Ok :: < _ , DataFusionError > ( ( ) )
1482- } ) ?;
1467+ // Only map statistics if schema_adapter_factory is explicitly set
1468+ // In DataFusion 52.1, SchemaAdapter has been removed and replaced with PhysicalExprAdapterFactory
1469+ // Statistics mapping is now optional and only done when explicitly configured
1470+ if let Some ( factory) = & self . schema_adapter_factory {
1471+ let schema_adapter = factory. create_with_projected_schema ( self . schema ( ) ) ;
1472+ let ( schema_mapper, _) = schema_adapter. map_schema ( self . file_schema . as_ref ( ) ) ?;
1473+
1474+ stats. column_statistics = schema_mapper. map_column_statistics ( & stats. column_statistics ) ?;
1475+ file_groups. iter_mut ( ) . try_for_each ( |file_group| {
1476+ if let Some ( stat) = file_group. statistics_mut ( ) {
1477+ stat. column_statistics = schema_mapper. map_column_statistics ( & stat. column_statistics ) ?;
1478+ }
1479+ Ok :: < _ , DataFusionError > ( ( ) )
1480+ } ) ?;
1481+ }
1482+
14831483 Ok ( ( file_groups, stats) )
14841484 }
14851485
0 commit comments