-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Implement readable explain plans for physical plans #337
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
cb74d9c
2b4aadb
fe06d35
3610906
f1ef298
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 |
|---|---|---|
|
|
@@ -356,13 +356,15 @@ pub enum Partitioning { | |
| /// after all children have been visited. | ||
| //// | ||
| /// To use, define a struct that implements this trait and then invoke | ||
| /// "LogicalPlan::accept". | ||
| /// [`LogicalPlan::accept`]. | ||
|
Contributor
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. Question: What this change does? better looking in the doc?
Member
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. It makes it an hyperlink in API docs :) |
||
| /// | ||
| /// For example, for a logical plan like: | ||
| /// | ||
| /// ```text | ||
| /// Projection: #id | ||
| /// Filter: #state Eq Utf8(\"CO\")\ | ||
| /// CsvScan: employee.csv projection=Some([0, 3])"; | ||
| /// ``` | ||
| /// | ||
| /// The sequence of visit operations would be: | ||
| /// ```text | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| // 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. | ||
|
|
||
| //! Implementation of physical plan display. See | ||
| //! [`crate::physical_plan::displayable`] for examples of how to | ||
| //! format | ||
|
|
||
| use std::fmt; | ||
|
|
||
| use super::{accept, ExecutionPlan, ExecutionPlanVisitor}; | ||
|
|
||
| /// Options for controlling how each [`ExecutionPlan`] should format itself | ||
| #[derive(Debug, Clone, Copy)] | ||
| pub enum DisplayFormatType { | ||
| /// Default, compact format. Example: `FilterExec: c12 < 10.0` | ||
| Default, | ||
|
Contributor
Author
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 envision adding more types (e.g. Graphviz) as needs evolve |
||
| } | ||
|
|
||
| /// Wraps an `ExecutionPlan` with various ways to display this plan | ||
| pub struct DisplayableExecutionPlan<'a> { | ||
| inner: &'a dyn ExecutionPlan, | ||
| } | ||
|
|
||
| impl<'a> DisplayableExecutionPlan<'a> { | ||
| /// Create a wrapper around an [`'ExecutionPlan'] which can be | ||
| /// pretty printed in a variety of ways | ||
| pub fn new(inner: &'a dyn ExecutionPlan) -> Self { | ||
| Self { inner } | ||
| } | ||
|
|
||
| /// Return a `format`able structure that produces a single line | ||
| /// per node. | ||
| /// | ||
| /// ```text | ||
| /// ProjectionExec: expr=[a] | ||
| /// CoalesceBatchesExec: target_batch_size=4096 | ||
| /// FilterExec: a < 5 | ||
| /// RepartitionExec: partitioning=RoundRobinBatch(16) | ||
| /// CsvExec: source=...", | ||
| /// ``` | ||
| pub fn indent(&self) -> impl fmt::Display + 'a { | ||
| struct Wrapper<'a>(&'a dyn ExecutionPlan); | ||
| impl<'a> fmt::Display for Wrapper<'a> { | ||
| fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
| let t = DisplayFormatType::Default; | ||
| let mut visitor = IndentVisitor { t, f, indent: 0 }; | ||
| accept(self.0, &mut visitor) | ||
| } | ||
| } | ||
| Wrapper(self.inner) | ||
| } | ||
| } | ||
|
|
||
| /// Formats plans with a single line per node. | ||
| struct IndentVisitor<'a, 'b> { | ||
| /// How to format each node | ||
| t: DisplayFormatType, | ||
| /// Write to this formatter | ||
| f: &'a mut fmt::Formatter<'b>, | ||
| ///with_schema: bool, | ||
| indent: usize, | ||
| } | ||
|
|
||
| impl<'a, 'b> ExecutionPlanVisitor for IndentVisitor<'a, 'b> { | ||
| type Error = fmt::Error; | ||
| fn pre_visit( | ||
| &mut self, | ||
| plan: &dyn ExecutionPlan, | ||
| ) -> std::result::Result<bool, Self::Error> { | ||
| write!(self.f, "{:indent$}", "", indent = self.indent * 2)?; | ||
| plan.fmt_as(self.t, self.f)?; | ||
| writeln!(self.f)?; | ||
| self.indent += 1; | ||
| Ok(true) | ||
| } | ||
| } | ||
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.
this is a better way to make indents that I found while googling around