Skip to content
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

Split SessionState into its own module #10794

Merged
merged 5 commits into from
Jun 6, 2024

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Jun 4, 2024

Which issue does this PR close?

Part of #10782

Rationale for this change

the datafusion/core/src/execution/context/mod.rs file is quite large and hard to navigate.

It would be better to have SessionContext and SessionState in their own modules

Also, if we ever are able to break out catalog from the core, e.g. #10782 we may have to break out SessionState as well, so having SessionState in its own module will help here

It also turns out splitting them into their own files makes the boundaries a bit clearer

What changes are included in this PR?

  1. Move SessionState out of datafusion/core/src/execution/context/mod.rs and into datafusion/core/src/execution/state.rs
  2. Add a pub use
  3. Add some additional accessors to SessionState to maintain the same behavior

Are these changes tested?

Exiting CI

Are there any user-facing changes?

No, this is an internal code reorganization only

@github-actions github-actions bot added the core Core DataFusion crate label Jun 4, 2024
@alamb alamb marked this pull request as draft June 4, 2024 20:29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we name it as session_state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in 0c1dbbe

@@ -1280,7 +1253,7 @@ impl SessionContext {
/// `query_execution_start_time` to the current time
pub fn state(&self) -> SessionState {
let mut state = self.state.read().clone();
state.execution_props.start_execution();
state.execution_props_mut().start_execution();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need mut here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is needed because the start execution method actually modifies the execution_props field -- when SessionContext was part of the same module, it could simply directly modify state.execution_props (the field, not a method)

Now that they are in separate modules, SessionContext can't modify SessionState internal fields directly.

So TLDR is that this code does the same as the previous version (modifies execution_props) but is more explicit about it, which I think is an improvement

Copy link
Contributor

@comphead comphead left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm thanks @alamb but this might require downstream user changes?

use url::Url;
use uuid::Uuid;

/// Execution context for registering data sources and executing queries.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just moved from context/mod.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

};
use sqlparser::dialect::dialect_from_str;

// backwards compatibility
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pub use means there should be no downstream changes required

@alamb
Copy link
Contributor Author

alamb commented Jun 5, 2024

lgtm thanks @alamb but this might require downstream user changes?

Sorry I should have pointed that out -- I left a pub use so I don't think this will require any downstream changes: https://github.com/apache/datafusion/pull/10794/files#r1628018164

@alamb alamb merged commit 82b4d1b into apache:main Jun 6, 2024
23 checks passed
@alamb
Copy link
Contributor Author

alamb commented Jun 6, 2024

Thanks again for the reviews

findepi pushed a commit to findepi/datafusion that referenced this pull request Jul 16, 2024
* Split `SessionState` into its own module

* fix docs

* fix test

* Rename state.rs to session_state.rs
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants