jayzhan211 commented on code in PR #11403:
URL: https://github.com/apache/datafusion/pull/11403#discussion_r1674856744
##########
datafusion/core/src/execution/session_state.rs:
##########
@@ -976,6 +837,482 @@ impl SessionState {
}
}
+/// A builder to be used for building [`SessionState`]'s. Defaults will be
used for all values
+/// unless explicitly provided. Note that there is no `Default` or `new()` for
SessionState,
+/// to avoid accidentally running queries or other operations without passing
through
+/// the [`SessionConfig`] or [`RuntimeEnv`].
+pub struct SessionStateBuilder {
+ state: SessionState,
+ use_defaults: bool,
+}
+
+impl SessionStateBuilder {
+ /// Returns new [`SessionStateBuilder`] using the provided
+ /// [`SessionConfig`] and [`RuntimeEnv`].
+ pub fn new_with_config_rt(
+ config: SessionConfig,
+ runtime_env: Arc<RuntimeEnv>,
+ ) -> Self {
+ let session_id = Uuid::new_v4().to_string();
+ let catalog_list =
+ Arc::new(MemoryCatalogProviderList::new()) as Arc<dyn
CatalogProviderList>;
+
+ Self {
+ state: SessionState {
+ session_id,
+ analyzer: Analyzer::new(),
+ expr_planners: vec![],
+ optimizer: Optimizer::new(),
+ physical_optimizers: PhysicalOptimizer::new(),
+ query_planner: Arc::new(DefaultQueryPlanner {}),
+ catalog_list,
+ table_functions: HashMap::new(),
+ scalar_functions: HashMap::new(),
+ aggregate_functions: HashMap::new(),
+ window_functions: HashMap::new(),
+ serializer_registry: Arc::new(EmptySerializerRegistry),
+ file_formats: HashMap::new(),
+ table_options: TableOptions::default_from_session_config(
+ config.options(),
+ ),
+ config,
+ execution_props: ExecutionProps::new(),
+ table_factories: HashMap::new(),
+ runtime_env,
+ function_factory: None,
+ },
+ use_defaults: true,
Review Comment:
If we have `default` by default, I think we don't need
`.with_defaults(true)` above
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]