MCPcopy Create free account
hub / github.com/apache/datafusion / explain_to_plan

Method explain_to_plan

datafusion/sql/src/statement.rs:2005–2058  ·  view source on GitHub ↗

Generate a plan for EXPLAIN ... that will print out a plan Note this is the sqlparser explain statement, not the datafusion `EXPLAIN` statement.

(
        &self,
        verbose: bool,
        analyze: bool,
        format: Option<String>,
        statement: DFStatement,
    )

Source from the content-addressed store, hash-verified

2003 /// Note this is the sqlparser explain statement, not the
2004 /// datafusion `EXPLAIN` statement.
2005 fn explain_to_plan(
2006 &self,
2007 verbose: bool,
2008 analyze: bool,
2009 format: Option<String>,
2010 statement: DFStatement,
2011 ) -> Result<LogicalPlan> {
2012 let plan = self.statement_to_plan(statement)?;
2013 if matches!(plan, LogicalPlan::Explain(_)) {
2014 return plan_err!("Nested EXPLAINs are not supported");
2015 }
2016
2017 let plan = Arc::new(plan);
2018 let schema = LogicalPlan::explain_schema();
2019 let schema = schema.to_dfschema_ref()?;
2020
2021 if verbose && format.is_some() {
2022 return plan_err!("EXPLAIN VERBOSE with FORMAT is not supported");
2023 }
2024
2025 if analyze {
2026 if format.is_some() {
2027 return plan_err!("EXPLAIN ANALYZE with FORMAT is not supported");
2028 }
2029 Ok(LogicalPlan::Analyze(Analyze {
2030 verbose,
2031 input: plan,
2032 schema,
2033 }))
2034 } else {
2035 let stringified_plans =
2036 vec![plan.to_stringified(PlanType::InitialLogicalPlan)];
2037
2038 // default to configuration value
2039 // verbose mode only supports indent format
2040 let options = self.context_provider.options();
2041 let format = if verbose {
2042 ExplainFormat::Indent
2043 } else if let Some(format) = format {
2044 ExplainFormat::from_str(&format)?
2045 } else {
2046 options.explain.format.clone()
2047 };
2048
2049 Ok(LogicalPlan::Explain(Explain {
2050 verbose,
2051 explain_format: format,
2052 plan,
2053 stringified_plans,
2054 schema,
2055 logical_optimization_succeeded: false,
2056 }))
2057 }
2058 }
2059
2060 fn show_variable_to_plan(&self, variable: &[Ident]) -> Result<LogicalPlan> {
2061 if !self.has_table("information_schema", "df_settings") {

Calls 8

newFunction · 0.85
AnalyzeClass · 0.85
from_strFunction · 0.85
ExplainClass · 0.85
to_dfschema_refMethod · 0.80
statement_to_planMethod · 0.45
optionsMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected