@@ -21,7 +21,6 @@ use datafusion_catalog::Session;
2121use datafusion_common:: { config_err, internal_err} ;
2222use datafusion_datasource:: ListingTableUrl ;
2323use datafusion_datasource:: file_compression_type:: FileCompressionType ;
24- use datafusion_datasource:: schema_adapter:: SchemaAdapterFactory ;
2524use datafusion_physical_expr_adapter:: PhysicalExprAdapterFactory ;
2625use std:: str:: FromStr ;
2726use std:: sync:: Arc ;
@@ -44,15 +43,12 @@ pub enum SchemaSource {
4443/// # Schema Evolution Support
4544///
4645/// This configuration supports schema evolution through the optional
47- /// [`SchemaAdapterFactory `]. You might want to override the default factory when you need:
46+ /// [`PhysicalExprAdapterFactory `]. You might want to override the default factory when you need:
4847///
4948/// - **Type coercion requirements**: When you need custom logic for converting between
5049/// different Arrow data types (e.g., Int32 ↔ Int64, Utf8 ↔ LargeUtf8)
5150/// - **Column mapping**: You need to map columns with a legacy name to a new name
5251/// - **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.
5652#[ derive( Debug , Clone , Default ) ]
5753pub struct ListingTableConfig {
5854 /// Paths on the `ObjectStore` for creating [`crate::ListingTable`].
@@ -68,8 +64,6 @@ pub struct ListingTableConfig {
6864 pub options : Option < ListingOptions > ,
6965 /// Tracks the source of the schema information
7066 pub ( crate ) schema_source : SchemaSource ,
71- /// Optional [`SchemaAdapterFactory`] for creating schema adapters
72- pub ( crate ) schema_adapter_factory : Option < Arc < dyn SchemaAdapterFactory > > ,
7367 /// Optional [`PhysicalExprAdapterFactory`] for creating physical expression adapters
7468 pub ( crate ) expr_adapter_factory : Option < Arc < dyn PhysicalExprAdapterFactory > > ,
7569}
@@ -218,8 +212,7 @@ impl ListingTableConfig {
218212 file_schema,
219213 options : _,
220214 schema_source,
221- schema_adapter_factory,
222- expr_adapter_factory : physical_expr_adapter_factory,
215+ expr_adapter_factory,
223216 } = self ;
224217
225218 let ( schema, new_schema_source) = match file_schema {
@@ -241,8 +234,7 @@ impl ListingTableConfig {
241234 file_schema : Some ( schema) ,
242235 options : Some ( options) ,
243236 schema_source : new_schema_source,
244- schema_adapter_factory,
245- expr_adapter_factory : physical_expr_adapter_factory,
237+ expr_adapter_factory,
246238 } )
247239 }
248240 None => internal_err ! ( "No `ListingOptions` set for inferring schema" ) ,
@@ -282,71 +274,18 @@ impl ListingTableConfig {
282274 file_schema : self . file_schema ,
283275 options : Some ( options) ,
284276 schema_source : self . schema_source ,
285- schema_adapter_factory : self . schema_adapter_factory ,
286277 expr_adapter_factory : self . expr_adapter_factory ,
287278 } )
288279 }
289280 None => config_err ! ( "No `ListingOptions` set for inferring schema" ) ,
290281 }
291282 }
292283
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-
340284 /// Set the [`PhysicalExprAdapterFactory`] for the [`crate::ListingTable`]
341285 ///
342286 /// The expression adapter factory is used to create physical expression adapters that can
343287 /// handle schema evolution and type conversions when evaluating expressions
344288 /// 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.
350289 pub fn with_expr_adapter_factory (
351290 self ,
352291 expr_adapter_factory : Arc < dyn PhysicalExprAdapterFactory > ,
0 commit comments