@@ -21,6 +21,7 @@ use datafusion_catalog::Session;
2121use datafusion_common:: { config_err, internal_err} ;
2222use datafusion_datasource:: ListingTableUrl ;
2323use datafusion_datasource:: file_compression_type:: FileCompressionType ;
24+ #[ expect( deprecated) ]
2425use datafusion_datasource:: schema_adapter:: SchemaAdapterFactory ;
2526use datafusion_physical_expr_adapter:: PhysicalExprAdapterFactory ;
2627use std:: str:: FromStr ;
@@ -44,15 +45,12 @@ pub enum SchemaSource {
4445/// # Schema Evolution Support
4546///
4647/// This configuration supports schema evolution through the optional
47- /// [`SchemaAdapterFactory `]. You might want to override the default factory when you need:
48+ /// [`PhysicalExprAdapterFactory `]. You might want to override the default factory when you need:
4849///
4950/// - **Type coercion requirements**: When you need custom logic for converting between
5051/// different Arrow data types (e.g., Int32 ↔ Int64, Utf8 ↔ LargeUtf8)
5152/// - **Column mapping**: You need to map columns with a legacy name to a new name
5253/// - **Custom handling of missing columns**: By default they are filled in with nulls, but you may e.g. want to fill them in with `0` or `""`.
53- ///
54- /// If not specified, a [`datafusion_datasource::schema_adapter::DefaultSchemaAdapterFactory`]
55- /// will be used, which handles basic schema compatibility cases.
5654#[ derive( Debug , Clone , Default ) ]
5755pub struct ListingTableConfig {
5856 /// Paths on the `ObjectStore` for creating [`crate::ListingTable`].
@@ -68,8 +66,6 @@ pub struct ListingTableConfig {
6866 pub options : Option < ListingOptions > ,
6967 /// Tracks the source of the schema information
7068 pub ( crate ) schema_source : SchemaSource ,
71- /// Optional [`SchemaAdapterFactory`] for creating schema adapters
72- pub ( crate ) schema_adapter_factory : Option < Arc < dyn SchemaAdapterFactory > > ,
7369 /// Optional [`PhysicalExprAdapterFactory`] for creating physical expression adapters
7470 pub ( crate ) expr_adapter_factory : Option < Arc < dyn PhysicalExprAdapterFactory > > ,
7571}
@@ -218,8 +214,7 @@ impl ListingTableConfig {
218214 file_schema,
219215 options : _,
220216 schema_source,
221- schema_adapter_factory,
222- expr_adapter_factory : physical_expr_adapter_factory,
217+ expr_adapter_factory,
223218 } = self ;
224219
225220 let ( schema, new_schema_source) = match file_schema {
@@ -241,8 +236,7 @@ impl ListingTableConfig {
241236 file_schema : Some ( schema) ,
242237 options : Some ( options) ,
243238 schema_source : new_schema_source,
244- schema_adapter_factory,
245- expr_adapter_factory : physical_expr_adapter_factory,
239+ expr_adapter_factory,
246240 } )
247241 }
248242 None => internal_err ! ( "No `ListingOptions` set for inferring schema" ) ,
@@ -282,71 +276,18 @@ impl ListingTableConfig {
282276 file_schema : self . file_schema ,
283277 options : Some ( options) ,
284278 schema_source : self . schema_source ,
285- schema_adapter_factory : self . schema_adapter_factory ,
286279 expr_adapter_factory : self . expr_adapter_factory ,
287280 } )
288281 }
289282 None => config_err ! ( "No `ListingOptions` set for inferring schema" ) ,
290283 }
291284 }
292285
293- /// Set the [`SchemaAdapterFactory`] for the [`crate::ListingTable`]
294- ///
295- /// The schema adapter factory is used to create schema adapters that can
296- /// handle schema evolution and type conversions when reading files with
297- /// different schemas than the table schema.
298- ///
299- /// If not provided, a default schema adapter factory will be used.
300- ///
301- /// # Example: Custom Schema Adapter for Type Coercion
302- /// ```rust
303- /// # use std::sync::Arc;
304- /// # use datafusion_catalog_listing::{ListingTableConfig, ListingOptions};
305- /// # use datafusion_datasource::schema_adapter::{SchemaAdapterFactory, SchemaAdapter};
306- /// # use datafusion_datasource::ListingTableUrl;
307- /// # use datafusion_datasource_parquet::file_format::ParquetFormat;
308- /// # use arrow::datatypes::{SchemaRef, Schema, Field, DataType};
309- /// #
310- /// # #[derive(Debug)]
311- /// # struct MySchemaAdapterFactory;
312- /// # impl SchemaAdapterFactory for MySchemaAdapterFactory {
313- /// # fn create(&self, _projected_table_schema: SchemaRef, _file_schema: SchemaRef) -> Box<dyn SchemaAdapter> {
314- /// # unimplemented!()
315- /// # }
316- /// # }
317- /// # let table_paths = ListingTableUrl::parse("file:///path/to/data").unwrap();
318- /// # let listing_options = ListingOptions::new(Arc::new(ParquetFormat::default()));
319- /// # let table_schema = Arc::new(Schema::new(vec![Field::new("id", DataType::Int64, false)]));
320- /// let config = ListingTableConfig::new(table_paths)
321- /// .with_listing_options(listing_options)
322- /// .with_schema(table_schema)
323- /// .with_schema_adapter_factory(Arc::new(MySchemaAdapterFactory));
324- /// ```
325- pub fn with_schema_adapter_factory (
326- self ,
327- schema_adapter_factory : Arc < dyn SchemaAdapterFactory > ,
328- ) -> Self {
329- Self {
330- schema_adapter_factory : Some ( schema_adapter_factory) ,
331- ..self
332- }
333- }
334-
335- /// Get the [`SchemaAdapterFactory`] for this configuration
336- pub fn schema_adapter_factory ( & self ) -> Option < & Arc < dyn SchemaAdapterFactory > > {
337- self . schema_adapter_factory . as_ref ( )
338- }
339-
340286 /// Set the [`PhysicalExprAdapterFactory`] for the [`crate::ListingTable`]
341287 ///
342288 /// The expression adapter factory is used to create physical expression adapters that can
343289 /// handle schema evolution and type conversions when evaluating expressions
344290 /// with different schemas than the table schema.
345- ///
346- /// If not provided, a default physical expression adapter factory will be used unless a custom
347- /// `SchemaAdapterFactory` is set, in which case only the `SchemaAdapterFactory` will be used.
348- ///
349- /// See <https://github.com/apache/datafusion/issues/16800> for details on this transition.
350291 pub fn with_expr_adapter_factory (
351292 self ,
352293 expr_adapter_factory : Arc < dyn PhysicalExprAdapterFactory > ,
@@ -356,4 +297,23 @@ impl ListingTableConfig {
356297 ..self
357298 }
358299 }
300+
301+ /// Deprecated: Set the [`SchemaAdapterFactory`] for the [`crate::ListingTable`]
302+ ///
303+ /// `SchemaAdapterFactory` has been removed. Use [`Self::with_expr_adapter_factory`]
304+ /// and `PhysicalExprAdapterFactory` instead. See `upgrading.md` for more details.
305+ ///
306+ /// This method is a no-op and returns `self` unchanged.
307+ #[ deprecated(
308+ since = "52.0.0" ,
309+ note = "SchemaAdapterFactory has been removed. Use with_expr_adapter_factory and PhysicalExprAdapterFactory instead. See upgrading.md for more details."
310+ ) ]
311+ #[ expect( deprecated) ]
312+ pub fn with_schema_adapter_factory (
313+ self ,
314+ _schema_adapter_factory : Arc < dyn SchemaAdapterFactory > ,
315+ ) -> Self {
316+ // No-op - just return self unchanged
317+ self
318+ }
359319}
0 commit comments