Skip to content

Commit

Permalink
feat: Support adding a single new table factory to SessionStateBuilder (
Browse files Browse the repository at this point in the history
  • Loading branch information
Weijun-H committed Sep 21, 2024
1 parent 21ec332 commit e5c0c0c
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions datafusion/core/src/execution/session_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1193,6 +1193,18 @@ impl SessionStateBuilder {
self
}

/// Add a [`TableProviderFactory`] to the map of factories
pub fn with_table_factory(
mut self,
key: String,
table_factory: Arc<dyn TableProviderFactory>,
) -> Self {
let mut table_factories = self.table_factories.unwrap_or_default();
table_factories.insert(key, table_factory);
self.table_factories = Some(table_factories);
self
}

/// Set the map of [`TableProviderFactory`]s
pub fn with_table_factories(
mut self,
Expand Down Expand Up @@ -1929,4 +1941,22 @@ mod tests {
Optimizer::default().rules.len() + 1
);
}

#[test]
fn test_with_table_factories() -> Result<()> {
use crate::test_util::TestTableFactory;

let state = SessionStateBuilder::new().build();
let table_factories = state.table_factories();
assert!(table_factories.is_empty());

let table_factory = Arc::new(TestTableFactory {});
let state = SessionStateBuilder::new()
.with_table_factory("employee".to_string(), table_factory)
.build();
let table_factories = state.table_factories();
assert_eq!(table_factories.len(), 1);
assert!(table_factories.contains_key("employee"));
Ok(())
}
}

0 comments on commit e5c0c0c

Please sign in to comment.