-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4ed9161
commit c500353
Showing
5 changed files
with
104 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod execute; | ||
pub mod analyze; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use std::pin::Pin; | ||
|
||
use spark_connect::{analyze_plan_response, AnalyzePlanResponse}; | ||
|
||
pub type AnalyzeStream = | ||
Pin<Box<dyn futures::Stream<Item = Result<AnalyzePlanResponse, Status>> + Send + Sync>>; | ||
|
||
use spark_connect::{analyze_plan_request::explain::ExplainMode, Relation}; | ||
use tonic::Status; | ||
|
||
use crate::{session::Session, translation}; | ||
|
||
pub struct PlanIds { | ||
session: String, | ||
server_side_session: String, | ||
} | ||
|
||
impl PlanIds { | ||
pub fn response(&self, result: analyze_plan_response::Result) -> AnalyzePlanResponse { | ||
AnalyzePlanResponse { | ||
session_id: self.session.to_string(), | ||
server_side_session_id: self.server_side_session.to_string(), | ||
result: Some(result), | ||
} | ||
} | ||
} | ||
|
||
impl Session { | ||
pub async fn handle_explain_command( | ||
&self, | ||
command: Relation, | ||
_mode: ExplainMode, | ||
) -> eyre::Result<AnalyzePlanResponse> { | ||
let context = PlanIds { | ||
session: self.client_side_session_id().to_string(), | ||
server_side_session: self.server_side_session_id().to_string(), | ||
}; | ||
|
||
let plan = translation::to_logical_plan(command)?; | ||
let optimized_plan = plan.optimize()?; | ||
|
||
let optimized_plan = optimized_plan.build(); | ||
|
||
// todo: what do we want this to display | ||
let explain_string = format!("{optimized_plan}"); | ||
|
||
let schema = analyze_plan_response::Explain { explain_string }; | ||
|
||
let response = context.response(analyze_plan_response::Result::Explain(schema)); | ||
Ok(response) | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from __future__ import annotations | ||
|
||
|
||
def test_explain(spark_session): | ||
# Create ranges using Spark - with overlap | ||
range1 = spark_session.range(7) # Creates DataFrame with numbers 0 to 6 | ||
range2 = spark_session.range(3, 10) # Creates DataFrame with numbers 3 to 9 | ||
|
||
# Union the two ranges | ||
unioned = range1.union(range2) | ||
|
||
# Get the explain plan | ||
explain_str = unioned.explain(extended=True) | ||
|
||
# Verify explain output contains expected elements | ||
print(explain_str) |