-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Minor: Move PlanType
, StringifiedPlan
and ToStringifiedPlan
datafusion_common
#6571
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
Changes from all commits
51d26d8
bbd4d7c
d1aa742
8cd30fb
0bb5777
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
/// `verbose_mode = true` will display all available plans | ||
pub fn should_display(&self, verbose_mode: bool) -> bool { | ||
match self.plan_type { | ||
PlanType::FinalLogicalPlan | PlanType::FinalPhysicalPlan => true, | ||
_ => verbose_mode, | ||
} | ||
} | ||
} | ||
|
||
/// Trait for something that can be formatted as a stringified plan | ||
pub trait ToStringifiedPlan { | ||
/// Create a stringified plan with the specified type | ||
fn to_stringified(&self, plan_type: PlanType) -> StringifiedPlan; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,7 +42,8 @@ use std::fmt::{self, Debug, Display, Formatter}; | |
use std::hash::{Hash, Hasher}; | ||
use std::sync::Arc; | ||
|
||
// backwards compatible | ||
// backwards compatibility | ||
pub use datafusion_common::display::{PlanType, StringifiedPlan, ToStringifiedPlan}; | ||
Comment on lines
+45
to
+46
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. For such things, I'm wondering as no deprecated message, it is possibly we can remove this kind of compatibility later? 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. I tried to add a deprecated message (that could point people to use the new location) but it didn't seem to work. I think we can remove the I guess I am hoping that over time we can remove some of the old 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. Yea, for such re-exported things, seems it is impossible to add deprecated message. So the only way is just to remove this kind of old APIs after some time (e.g., few releases?). |
||
pub use datafusion_common::{JoinConstraint, JoinType}; | ||
|
||
use super::DdlStatement; | ||
|
@@ -1650,93 +1651,6 @@ pub enum Partitioning { | |
DistributeBy(Vec<Expr>), | ||
} | ||
|
||
/// 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 | ||
/// `verbose_mode = true` will display all available plans | ||
pub fn should_display(&self, verbose_mode: bool) -> bool { | ||
match self.plan_type { | ||
PlanType::FinalLogicalPlan | PlanType::FinalPhysicalPlan => true, | ||
_ => verbose_mode, | ||
} | ||
} | ||
} | ||
|
||
/// Trait for something that can be formatted as a stringified plan | ||
pub trait ToStringifiedPlan { | ||
/// Create a stringified plan with the specified type | ||
fn to_stringified(&self, plan_type: PlanType) -> StringifiedPlan; | ||
} | ||
|
||
/// Unnest a column that contains a nested list type. | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash)] | ||
pub struct Unnest { | ||
|
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.
the whole point of this PR is to remove the
logical_expr
from theuse
statements inphysical_plan