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

fix: adds more information when an EXPLAIN <query> is run on a federated source #34

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion datafusion-federation/src/plan_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ impl UserDefinedLogicalNodeCore for FederatedPlanNode {
}

fn fmt_for_explain(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Federated")
write!(f, "Federated\n {:?}", self.plan)
}

fn from_template(&self, exprs: &[Expr], inputs: &[LogicalPlan]) -> Self {
Expand Down
11 changes: 10 additions & 1 deletion examples/examples/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,17 @@ async fn main() -> datafusion::error::Result<()> {
JOIN Artist ar ON a.ArtistId = ar.ArtistId
limit 10"#;
let df = ctx.sql(query).await?;
df.show().await?;

df.show().await
// If the environment variable EXPLAIN is set, print the query plan
if std::env::var("EXPLAIN").is_ok() {
let explain_query = format!("EXPLAIN {query}");
let df = ctx.sql(explain_query.as_str()).await?;

df.show().await?;
}

Ok(())
}

fn overwrite_default_schema(state: &SessionState, schema: Arc<dyn SchemaProvider>) -> Result<()> {
Expand Down
10 changes: 9 additions & 1 deletion sources/sql/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,15 @@ impl VirtualExecutionPlan {

impl DisplayAs for VirtualExecutionPlan {
fn fmt_as(&self, _t: DisplayFormatType, f: &mut fmt::Formatter) -> std::fmt::Result {
write!(f, "VirtualExecutionPlan")
write!(f, "VirtualExecutionPlan")?;
let Ok(ast) = plan_to_sql(&self.plan) else {
return Ok(());
};
write!(f, " name={}", self.executor.name())?;
if let Some(ctx) = self.executor.compute_context() {
write!(f, " compute_context={ctx}")?;
}
write!(f, " sql={ast}")
}
}

Expand Down
Loading