-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Set query_execution_start_time on snapshot from SessionContext (#4747) #4750
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1000,23 +1000,7 @@ impl SessionContext { | |
| &self, | ||
| logical_plan: &LogicalPlan, | ||
| ) -> Result<Arc<dyn ExecutionPlan>> { | ||
| let state_cloned = { | ||
| let mut state = self.state.write(); | ||
| state.execution_props.start_execution(); | ||
|
|
||
| // We need to clone `state` to release the lock that is not `Send`. We could | ||
| // make the lock `Send` by using `tokio::sync::Mutex`, but that would require to | ||
| // propagate async even to the `LogicalPlan` building methods. | ||
| // Cloning `state` here is fine as we then pass it as immutable `&state`, which | ||
| // means that we avoid write consistency issues as the cloned version will not | ||
| // be written to. As for eventual modifications that would be applied to the | ||
| // original state after it has been cloned, they will not be picked up by the | ||
| // clone but that is okay, as it is equivalent to postponing the state update | ||
| // by keeping the lock until the end of the function scope. | ||
| state.clone() | ||
| }; | ||
|
|
||
| state_cloned.create_physical_plan(logical_plan).await | ||
| self.state().create_physical_plan(logical_plan).await | ||
| } | ||
|
|
||
| /// Executes a query and writes the results to a partitioned CSV file. | ||
|
|
@@ -1055,9 +1039,12 @@ impl SessionContext { | |
| Arc::new(TaskContext::from(self)) | ||
| } | ||
|
|
||
| /// Get a copy of the [`SessionState`] of this [`SessionContext`] | ||
| /// Snapshots the [`SessionState`] of this [`SessionContext`] setting the | ||
| /// `query_execution_start_time` to the current time | ||
| pub fn state(&self) -> SessionState { | ||
| self.state.read().clone() | ||
| let mut state = self.state.read().clone(); | ||
| state.execution_props.start_execution(); | ||
|
Contributor
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 is a nice change 👍 make sense |
||
| state | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ | |
| // under the License. | ||
|
|
||
| use crate::var_provider::{VarProvider, VarType}; | ||
| use chrono::{DateTime, Utc}; | ||
| use chrono::{DateTime, TimeZone, Utc}; | ||
| use std::collections::HashMap; | ||
| use std::sync::Arc; | ||
|
|
||
|
|
@@ -44,14 +44,16 @@ impl ExecutionProps { | |
| /// Creates a new execution props | ||
| pub fn new() -> Self { | ||
| ExecutionProps { | ||
| query_execution_start_time: chrono::Utc::now(), | ||
| // Set this to a fixed sentinel to make it obvious if this is | ||
| // not being updated / propagated correctly | ||
|
Contributor
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. 👍 |
||
| query_execution_start_time: Utc.timestamp_nanos(0), | ||
| var_providers: None, | ||
| } | ||
| } | ||
|
|
||
| /// Marks the execution of query started timestamp | ||
| pub fn start_execution(&mut self) -> &Self { | ||
| self.query_execution_start_time = chrono::Utc::now(); | ||
| self.query_execution_start_time = Utc::now(); | ||
| &*self | ||
| } | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
I no longer intend to do this, as it creates far too much churn to justify it, this PR instead opts to workaround the issue by punting responsibility for setting the execution start time onto the caller if they're using the lower-level APIs.