This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new e5c0c0ca74 feat: Support adding a single new table factory to
SessionStateBuilder (#12563)
e5c0c0ca74 is described below
commit e5c0c0ca74e626178caf32c578c0580c0d4f1fe6
Author: Alex Huang <[email protected]>
AuthorDate: Sat Sep 21 18:20:46 2024 +0800
feat: Support adding a single new table factory to SessionStateBuilder
(#12563)
---
datafusion/core/src/execution/session_state.rs | 30 ++++++++++++++++++++++++++
1 file changed, 30 insertions(+)
diff --git a/datafusion/core/src/execution/session_state.rs
b/datafusion/core/src/execution/session_state.rs
index f656fae401..a46e5c3615 100644
--- a/datafusion/core/src/execution/session_state.rs
+++ b/datafusion/core/src/execution/session_state.rs
@@ -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,
@@ -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(())
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]