Skip to content

Commit

Permalink
refactor(plan_node_fmt): further prepare generic code where they use …
Browse files Browse the repository at this point in the history
…`fmt_with_name` (#10157)
  • Loading branch information
ice1000 authored and kwannoel committed Jun 6, 2023
1 parent fd5a0b4 commit 074252d
Show file tree
Hide file tree
Showing 32 changed files with 131 additions and 225 deletions.
9 changes: 2 additions & 7 deletions src/frontend/src/optimizer/plan_node/batch_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::DeleteNode;

use super::utils::impl_distill_by_unit;
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
Expand All @@ -43,11 +42,7 @@ impl BatchDelete {
}
}

impl fmt::Display for BatchDelete {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchDelete")
}
}
impl_distill_by_unit!(BatchDelete, logical, "BatchDelete");

impl PlanTreeNodeUnary for BatchDelete {
fn input(&self) -> PlanRef {
Expand Down
31 changes: 29 additions & 2 deletions src/frontend/src/optimizer/plan_node/batch_exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

use std::fmt;

use pretty_xmlish::Pretty;
use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::{ExchangeNode, MergeSortExchangeNode};

use super::utils::Distill;
use super::{ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::optimizer::plan_node::ToLocalBatch;
use crate::optimizer::property::{Distribution, DistributionDisplay, Order, OrderDisplay};
Expand All @@ -41,20 +43,45 @@ impl BatchExchange {

impl fmt::Display for BatchExchange {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let input_schema = self.input.schema();
write!(
f,
"BatchExchange {{ order: {}, dist: {} }}",
OrderDisplay {
order: &self.base.order,
input_schema: self.input.schema()
input_schema
},
DistributionDisplay {
distribution: &self.base.dist,
input_schema: self.input.schema()
input_schema
}
)
}
}
impl Distill for BatchExchange {
fn distill<'a>(&self) -> Pretty<'a> {
let input_schema = self.input.schema();
Pretty::childless_record(
"BatchExchange",
vec![
(
"order",
Pretty::display(&OrderDisplay {
order: &self.base.order,
input_schema,
}),
),
(
"dist",
Pretty::display(&DistributionDisplay {
distribution: &self.base.dist,
input_schema,
}),
),
],
)
}
}

impl PlanTreeNodeUnary for BatchExchange {
fn input(&self) -> PlanRef {
Expand Down
9 changes: 2 additions & 7 deletions src/frontend/src/optimizer/plan_node/batch_expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use itertools::Itertools;
use risingwave_common::error::Result;
use risingwave_pb::batch_plan::expand_node::Subset;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::ExpandNode;

use super::utils::impl_distill_by_unit;
use super::{generic, ExprRewritable};
use crate::optimizer::plan_node::{
PlanBase, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch, ToLocalBatch,
Expand Down Expand Up @@ -51,11 +50,7 @@ impl BatchExpand {
}
}

impl fmt::Display for BatchExpand {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchExpand")
}
}
impl_distill_by_unit!(BatchExpand, logical, "BatchExpand");

impl PlanTreeNodeUnary for BatchExpand {
fn input(&self) -> PlanRef {
Expand Down
10 changes: 2 additions & 8 deletions src/frontend/src/optimizer/plan_node/batch_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::FilterNode;

use super::utils::impl_distill_by_unit;
use super::{generic, ExprRewritable, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::expr::{Expr, ExprImpl, ExprRewriter};
use crate::optimizer::plan_node::{PlanBase, ToLocalBatch};
Expand Down Expand Up @@ -45,12 +44,7 @@ impl BatchFilter {
&self.logical.predicate
}
}

impl fmt::Display for BatchFilter {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchFilter")
}
}
impl_distill_by_unit!(BatchFilter, logical, "BatchFilter");

impl PlanTreeNodeUnary for BatchFilter {
fn input(&self) -> PlanRef {
Expand Down
9 changes: 2 additions & 7 deletions src/frontend/src/optimizer/plan_node/batch_group_topn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::GroupTopNNode;

use super::utils::impl_distill_by_unit;
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
Expand Down Expand Up @@ -47,11 +46,7 @@ impl BatchGroupTopN {
}
}

impl fmt::Display for BatchGroupTopN {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchGroupTopN")
}
}
impl_distill_by_unit!(BatchGroupTopN, logical, "BatchGroupTopN");

impl PlanTreeNodeUnary for BatchGroupTopN {
fn input(&self) -> PlanRef {
Expand Down
9 changes: 2 additions & 7 deletions src/frontend/src/optimizer/plan_node/batch_hash_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use fixedbitset::FixedBitSet;
use itertools::Itertools;
use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::HashAggNode;

use super::generic::{self, GenericPlanRef, PlanAggCall};
use super::utils::impl_distill_by_unit;
use super::{
ExprRewritable, PlanBase, PlanNodeType, PlanRef, PlanTreeNodeUnary, ToBatchPb,
ToDistributedBatch,
Expand Down Expand Up @@ -100,11 +99,7 @@ impl BatchHashAgg {
}
}

impl fmt::Display for BatchHashAgg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchHashAgg")
}
}
impl_distill_by_unit!(BatchHashAgg, logical, "BatchHashAgg");

impl PlanTreeNodeUnary for BatchHashAgg {
fn input(&self) -> PlanRef {
Expand Down
10 changes: 2 additions & 8 deletions src/frontend/src/optimizer/plan_node/batch_hop_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::HopWindowNode;

use super::utils::impl_distill_by_unit;
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
Expand Down Expand Up @@ -58,12 +57,7 @@ impl BatchHopWindow {
}
}
}

impl fmt::Display for BatchHopWindow {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchHopWindow")
}
}
impl_distill_by_unit!(BatchHopWindow, logical, "BatchHopWindow");

impl PlanTreeNodeUnary for BatchHopWindow {
fn input(&self) -> PlanRef {
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/optimizer/plan_node/batch_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ impl fmt::Display for BatchInsert {
self.logical.fmt_with_name(f, "BatchInsert")
}
}
// impl_distill_by_unit!(BatchInsert, logical, "BatchInsert");

impl PlanTreeNodeUnary for BatchInsert {
fn input(&self) -> PlanRef {
Expand Down
9 changes: 2 additions & 7 deletions src/frontend/src/optimizer/plan_node/batch_project_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use itertools::Itertools;
use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::ProjectSetNode;

use super::utils::impl_distill_by_unit;
use super::{generic, ExprRewritable};
use crate::expr::ExprRewriter;
use crate::optimizer::plan_node::{
Expand Down Expand Up @@ -48,11 +47,7 @@ impl BatchProjectSet {
}
}

impl fmt::Display for BatchProjectSet {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchProjectSet")
}
}
impl_distill_by_unit!(BatchProjectSet, logical, "BatchProjectSet");

impl PlanTreeNodeUnary for BatchProjectSet {
fn input(&self) -> PlanRef {
Expand Down
10 changes: 2 additions & 8 deletions src/frontend/src/optimizer/plan_node/batch_simple_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::SortAggNode;

use super::generic::{self, PlanAggCall};
use super::utils::impl_distill_by_unit;
use super::{ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::expr::ExprRewriter;
use crate::optimizer::plan_node::{BatchExchange, ToLocalBatch};
Expand Down Expand Up @@ -50,12 +49,7 @@ impl BatchSimpleAgg {
self.logical.can_two_phase_agg() && self.two_phase_agg_enabled()
}
}

impl fmt::Display for BatchSimpleAgg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchSimpleAgg")
}
}
impl_distill_by_unit!(BatchSimpleAgg, logical, "BatchSimpleAgg");

impl PlanTreeNodeUnary for BatchSimpleAgg {
fn input(&self) -> PlanRef {
Expand Down
10 changes: 2 additions & 8 deletions src/frontend/src/optimizer/plan_node/batch_sort_agg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use fixedbitset::FixedBitSet;
use itertools::Itertools;
use risingwave_common::error::Result;
Expand All @@ -22,6 +20,7 @@ use risingwave_pb::batch_plan::SortAggNode;
use risingwave_pb::expr::ExprNode;

use super::generic::{self, GenericPlanRef, PlanAggCall};
use super::utils::impl_distill_by_unit;
use super::{ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch};
use crate::expr::{Expr, ExprImpl, ExprRewriter, InputRef};
use crate::optimizer::plan_node::ToLocalBatch;
Expand Down Expand Up @@ -78,12 +77,7 @@ impl BatchSortAgg {
&self.logical.group_key
}
}

impl fmt::Display for BatchSortAgg {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchSortAgg")
}
}
impl_distill_by_unit!(BatchSortAgg, logical, "BatchSortAgg");

impl PlanTreeNodeUnary for BatchSortAgg {
fn input(&self) -> PlanRef {
Expand Down
9 changes: 2 additions & 7 deletions src/frontend/src/optimizer/plan_node/batch_topn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::TopNNode;

use super::generic::Limit;
use super::utils::impl_distill_by_unit;
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
Expand Down Expand Up @@ -79,11 +78,7 @@ impl BatchTopN {
}
}

impl fmt::Display for BatchTopN {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchTopN")
}
}
impl_distill_by_unit!(BatchTopN, logical, "BatchTopN");

impl PlanTreeNodeUnary for BatchTopN {
fn input(&self) -> PlanRef {
Expand Down
9 changes: 2 additions & 7 deletions src/frontend/src/optimizer/plan_node/batch_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use std::fmt;

use risingwave_common::catalog::Schema;
use risingwave_common::error::Result;
use risingwave_pb::batch_plan::plan_node::NodeBody;
use risingwave_pb::batch_plan::UpdateNode;

use super::utils::impl_distill_by_unit;
use super::{
generic, ExprRewritable, PlanBase, PlanRef, PlanTreeNodeUnary, ToBatchPb, ToDistributedBatch,
};
Expand All @@ -41,11 +40,7 @@ impl BatchUpdate {
}
}

impl fmt::Display for BatchUpdate {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.logical.fmt_with_name(f, "BatchUpdate")
}
}
impl_distill_by_unit!(BatchUpdate, logical, "BatchUpdate");

impl PlanTreeNodeUnary for BatchUpdate {
fn input(&self) -> PlanRef {
Expand Down
Loading

0 comments on commit 074252d

Please sign in to comment.