@@ -85,3 +85,56 @@ pub(super) fn check_inputs_len(
8585 ) ) )
8686 }
8787}
88+
89+ // Macro for applying a block to all enum variants
90+ macro_rules! match_plan_node {
91+ ( $self: expr, $node: ident => $block: block) => {
92+ match $self {
93+ PlanNode :: Query ( $node) => $block,
94+ PlanNode :: LogicalJoin ( $node) => $block,
95+ PlanNode :: FullKeyAggregate ( $node) => $block,
96+ PlanNode :: PreAggregation ( $node) => $block,
97+ PlanNode :: ResolveMultipliedMeasures ( $node) => $block,
98+ PlanNode :: AggregateMultipliedSubquery ( $node) => $block,
99+ PlanNode :: Cube ( $node) => $block,
100+ PlanNode :: MeasureSubquery ( $node) => $block,
101+ PlanNode :: DimensionSubQuery ( $node) => $block,
102+ PlanNode :: KeysSubQuery ( $node) => $block,
103+ PlanNode :: MultiStageGetDateRange ( $node) => $block,
104+ PlanNode :: MultiStageLeafMeasure ( $node) => $block,
105+ PlanNode :: MultiStageMeasureCalculation ( $node) => $block,
106+ PlanNode :: MultiStageTimeSeries ( $node) => $block,
107+ PlanNode :: MultiStageRollingWindow ( $node) => $block,
108+ PlanNode :: LogicalMultiStageMember ( $node) => $block,
109+ }
110+ } ;
111+ }
112+
113+ impl LogicalNode for PlanNode {
114+ fn inputs ( & self ) -> Vec < PlanNode > {
115+ match_plan_node ! ( self , node => {
116+ node. inputs( )
117+ } )
118+ }
119+
120+ fn node_name ( & self ) -> & ' static str {
121+ match_plan_node ! ( self , node => {
122+ node. node_name( )
123+ } )
124+ }
125+
126+ fn with_inputs ( self : Rc < Self > , inputs : Vec < PlanNode > ) -> Result < Rc < Self > , CubeError > {
127+ let result = match_plan_node ! ( self . as_ref( ) , node => {
128+ node. clone( ) . with_inputs( inputs) ?. as_plan_node( )
129+ } ) ;
130+ Ok ( Rc :: new ( result) )
131+ }
132+
133+ fn try_from_plan_node ( plan_node : PlanNode ) -> Result < Rc < Self > , CubeError > {
134+ Ok ( Rc :: new ( plan_node) )
135+ }
136+
137+ fn as_plan_node ( self : & Rc < Self > ) -> PlanNode {
138+ ( * * self ) . clone ( )
139+ }
140+ }
0 commit comments