Skip to content

Commit cbd63d9

Browse files
alambSruhvx-jpg
andauthored
[branch-56] feat: Add expr_adapter_factory getter and with_expr_adapter_factory setter on ListingTable (backport #27317) (#27369)
## Which issue does this PR close? - part of #24461 - Backport of #27317 to `branch-56` - Related to #27314. Co-authored-by: Sruhvx <[email protected]>
1 parent 3f197fe commit cbd63d9

1 file changed

Lines changed: 60 additions & 0 deletions

File tree

‎datafusion/catalog-listing/src/table.rs‎

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,20 @@ impl ListingTable {
340340
self
341341
}
342342

343+
/// Returns the [`PhysicalExprAdapterFactory`] used by this [`ListingTable`], if set.
344+
pub fn expr_adapter_factory(&self) -> Option<&Arc<dyn PhysicalExprAdapterFactory>> {
345+
self.expr_adapter_factory.as_ref()
346+
}
347+
348+
/// Set the [`PhysicalExprAdapterFactory`] for this [`ListingTable`].
349+
pub fn with_expr_adapter_factory(
350+
mut self,
351+
expr_adapter_factory: Arc<dyn PhysicalExprAdapterFactory>,
352+
) -> Self {
353+
self.expr_adapter_factory = Some(expr_adapter_factory);
354+
self
355+
}
356+
343357
/// Deprecated: Returns the [`SchemaAdapterFactory`] used by this [`ListingTable`].
344358
///
345359
/// `SchemaAdapterFactory` has been removed. Use `PhysicalExprAdapterFactory` instead.
@@ -1264,9 +1278,25 @@ async fn get_files_with_limit(
12641278
mod tests {
12651279
use super::*;
12661280
use arrow::compute::SortOptions;
1281+
use arrow::datatypes::Schema;
1282+
use datafusion_datasource_parquet::ParquetFormat;
12671283
use datafusion_physical_expr::expressions::Column;
1284+
use datafusion_physical_expr_adapter::DefaultPhysicalExprAdapterFactory;
12681285
use datafusion_physical_expr_common::sort_expr::PhysicalSortExpr;
12691286

1287+
fn create_test_listing_table() -> ListingTable {
1288+
let table_path = ListingTableUrl::parse("file:///test").unwrap();
1289+
let file_format = Arc::new(ParquetFormat::default());
1290+
let listing_options = ListingOptions::new(file_format);
1291+
let schema = Arc::new(Schema::empty());
1292+
1293+
let config = ListingTableConfig::new(table_path)
1294+
.with_listing_options(listing_options)
1295+
.with_schema(schema);
1296+
1297+
ListingTable::try_new(config).unwrap()
1298+
}
1299+
12701300
/// Helper to create a PhysicalSortExpr
12711301
fn sort_expr(
12721302
name: &str,
@@ -1421,4 +1451,34 @@ mod tests {
14211451
let result = derive_common_ordering_from_files(&file_groups);
14221452
assert_eq!(result, Some(ordering));
14231453
}
1454+
1455+
#[test]
1456+
fn test_with_expr_adapter_factory() {
1457+
let factory1: Arc<dyn PhysicalExprAdapterFactory> =
1458+
Arc::new(DefaultPhysicalExprAdapterFactory);
1459+
let factory2: Arc<dyn PhysicalExprAdapterFactory> =
1460+
Arc::new(DefaultPhysicalExprAdapterFactory);
1461+
1462+
let table =
1463+
create_test_listing_table().with_expr_adapter_factory(Arc::clone(&factory1));
1464+
1465+
assert!(Arc::ptr_eq(
1466+
table.expr_adapter_factory().unwrap(),
1467+
&factory1
1468+
));
1469+
1470+
let updated_table = table
1471+
.clone()
1472+
.with_expr_adapter_factory(Arc::clone(&factory2));
1473+
1474+
assert!(Arc::ptr_eq(
1475+
updated_table.expr_adapter_factory().unwrap(),
1476+
&factory2
1477+
));
1478+
1479+
assert!(Arc::ptr_eq(
1480+
table.expr_adapter_factory().unwrap(),
1481+
&factory1
1482+
));
1483+
}
14241484
}

0 commit comments

Comments
 (0)