viirya commented on code in PR #6571: URL: https://github.com/apache/arrow-datafusion/pull/6571#discussion_r1225164236
########## datafusion/common/src/display.rs: ########## @@ -0,0 +1,110 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +//! Types for plan display + +use std::{ + fmt::{self, Display, Formatter}, + sync::Arc, +}; + +/// Represents which type of plan, when storing multiple +/// for use in EXPLAIN plans +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub enum PlanType { + /// The initial LogicalPlan provided to DataFusion + InitialLogicalPlan, + /// The LogicalPlan which results from applying an analyzer pass + AnalyzedLogicalPlan { + /// The name of the analyzer which produced this plan + analyzer_name: String, + }, + /// The LogicalPlan after all analyzer passes have been applied + FinalAnalyzedLogicalPlan, + /// The LogicalPlan which results from applying an optimizer pass + OptimizedLogicalPlan { + /// The name of the optimizer which produced this plan + optimizer_name: String, + }, + /// The final, fully optimized LogicalPlan that was converted to a physical plan + FinalLogicalPlan, + /// The initial physical plan, prepared for execution + InitialPhysicalPlan, + /// The ExecutionPlan which results from applying an optimizer pass + OptimizedPhysicalPlan { + /// The name of the optimizer which produced this plan + optimizer_name: String, + }, + /// The final, fully optimized physical which would be executed + FinalPhysicalPlan, +} + +impl Display for PlanType { + fn fmt(&self, f: &mut Formatter) -> fmt::Result { + match self { + PlanType::InitialLogicalPlan => write!(f, "initial_logical_plan"), + PlanType::AnalyzedLogicalPlan { analyzer_name } => { + write!(f, "logical_plan after {analyzer_name}") + } + PlanType::FinalAnalyzedLogicalPlan => write!(f, "analyzed_logical_plan"), + PlanType::OptimizedLogicalPlan { optimizer_name } => { + write!(f, "logical_plan after {optimizer_name}") + } + PlanType::FinalLogicalPlan => write!(f, "logical_plan"), + PlanType::InitialPhysicalPlan => write!(f, "initial_physical_plan"), + PlanType::OptimizedPhysicalPlan { optimizer_name } => { + write!(f, "physical_plan after {optimizer_name}") + } + PlanType::FinalPhysicalPlan => write!(f, "physical_plan"), + } + } +} + +/// Represents some sort of execution plan, in String form +#[derive(Debug, Clone, PartialEq, Eq, Hash)] +pub struct StringifiedPlan { + /// An identifier of what type of plan this string represents + pub plan_type: PlanType, + /// The string representation of the plan + pub plan: Arc<String>, +} + +impl StringifiedPlan { + /// Create a new Stringified plan of `plan_type` with string + /// representation `plan` + pub fn new(plan_type: PlanType, plan: impl Into<String>) -> Self { + StringifiedPlan { + plan_type, + plan: Arc::new(plan.into()), + } + } + + /// returns true if this plan should be displayed. Generally Review Comment: nit: it was so previously, but seems good to revise it for style consistency ```suggestion /// Returns true if this plan should be displayed. Generally ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
