-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SessionStateBuilder and extract out the registration of defaults #11403
Changes from all commits
fab06da
de39082
7d1bc09
490214d
93a3a7d
e3fad6d
8a579cf
eb64e2f
71decf6
380ce98
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,6 +73,7 @@ use object_store::ObjectStore; | |
use parking_lot::RwLock; | ||
use url::Url; | ||
|
||
use crate::execution::session_state::SessionStateBuilder; | ||
pub use datafusion_execution::config::SessionConfig; | ||
pub use datafusion_execution::TaskContext; | ||
pub use datafusion_expr::execution_props::ExecutionProps; | ||
|
@@ -294,7 +295,11 @@ impl SessionContext { | |
/// all `SessionContext`'s should be configured with the | ||
/// same `RuntimeEnv`. | ||
pub fn new_with_config_rt(config: SessionConfig, runtime: Arc<RuntimeEnv>) -> Self { | ||
let state = SessionState::new_with_config_rt(config, runtime); | ||
let state = SessionStateBuilder::new() | ||
.with_config(config) | ||
.with_runtime_env(runtime) | ||
.with_default_features() | ||
.build(); | ||
Self::new_with_state(state) | ||
} | ||
|
||
|
@@ -315,7 +320,7 @@ impl SessionContext { | |
} | ||
|
||
/// Creates a new `SessionContext` using the provided [`SessionState`] | ||
#[deprecated(since = "32.0.0", note = "Use SessionState::new_with_state")] | ||
#[deprecated(since = "32.0.0", note = "Use SessionContext::new_with_state")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a follow on PR perhaps we can remove this API entirely We could probably change the note to say say "SessionStateBuilder" |
||
pub fn with_state(state: SessionState) -> Self { | ||
Self::new_with_state(state) | ||
} | ||
|
@@ -1574,6 +1579,7 @@ mod tests { | |
use datafusion_common_runtime::SpawnedTask; | ||
|
||
use crate::catalog::schema::SchemaProvider; | ||
use crate::execution::session_state::SessionStateBuilder; | ||
use crate::physical_planner::PhysicalPlanner; | ||
use async_trait::async_trait; | ||
use tempfile::TempDir; | ||
|
@@ -1707,7 +1713,11 @@ mod tests { | |
.set_str("datafusion.catalog.location", url.as_str()) | ||
.set_str("datafusion.catalog.format", "CSV") | ||
.set_str("datafusion.catalog.has_header", "true"); | ||
let session_state = SessionState::new_with_config_rt(cfg, runtime); | ||
let session_state = SessionStateBuilder::new() | ||
.with_config(cfg) | ||
.with_runtime_env(runtime) | ||
.with_default_features() | ||
.build(); | ||
let ctx = SessionContext::new_with_state(session_state); | ||
ctx.refresh_catalogs().await?; | ||
|
||
|
@@ -1733,9 +1743,12 @@ mod tests { | |
#[tokio::test] | ||
async fn custom_query_planner() -> Result<()> { | ||
let runtime = Arc::new(RuntimeEnv::default()); | ||
let session_state = | ||
SessionState::new_with_config_rt(SessionConfig::new(), runtime) | ||
.with_query_planner(Arc::new(MyQueryPlanner {})); | ||
let session_state = SessionStateBuilder::new() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this just looks so much nicer |
||
.with_config(SessionConfig::new()) | ||
.with_runtime_env(runtime) | ||
.with_default_features() | ||
.with_query_planner(Arc::new(MyQueryPlanner {})) | ||
.build(); | ||
let ctx = SessionContext::new_with_state(session_state); | ||
|
||
let df = ctx.sql("SELECT 1").await?; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this code previously always registered the table options and now it only registers them if another table option was registered. Is that intentional?
Maybe it doesn't matter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well .... I updated all of the existing code in the project to reflect the change but I agree that it may be a bit of a surprise to anyone expecting the old behavior when upgrading. 6 of one, 1/2 dozen of another ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, sorry, misread the comment. I think it works only because the builder was created from an existing session state.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can clean it up as a follow on -- it is not critical in my opinion