Skip to content

Split SessionState into its own module - #10794

Merged
alamb merged 5 commits into
apache:mainfrom
alamb:alamb/split_session_state
Jun 6, 2024
Merged

alamb merged 5 commits into
apache:mainfrom
alamb:alamb/split_session_state

Conversation

@alamb

@alamb alamb commented Jun 4, 2024

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in 0c1dbbe

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
Copy Markdown
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
Copy Markdown
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

@comphead comphead left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

alamb commented Jun 5, 2024

Copy link
Copy Markdown
Contributor Author

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
@alamb

alamb commented Jun 6, 2024

Copy link
Copy Markdown
Contributor Author

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
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