1
- /// Plan nodes with data fields must implement `ExplainData` trait.
2
- ///
3
- /// The generated `dispatch_explain` method delegates explaining data to
4
- /// rel node implementations of `ExplainData` trait instead of just debug
5
- /// printing it, because for complex data type (struct), derived debug printing
6
- /// displays struct name which should be hidden from the user. It also wraps
7
- /// the fields in braces, unlike the rest of the fields as children.
8
-
9
1
macro_rules! define_plan_node {
10
2
(
11
3
$struct_name: ident : $meta_typ: tt,
@@ -39,7 +31,7 @@ macro_rules! define_plan_node {
39
31
if let Some ( meta_map) = meta_map {
40
32
fields = fields. with_meta( self . 0 . get_meta( meta_map) ) ;
41
33
} ;
42
- define_plan_node!( @expand_data_fields self , $struct_name, fields $( , $data_name ) ?) ;
34
+ define_plan_node!( @expand_data_fields self , $struct_name, fields $( , $data_typ ) ?) ;
43
35
44
36
pretty_xmlish:: Pretty :: simple_record(
45
37
stringify!( $struct_name) ,
@@ -61,7 +53,7 @@ macro_rules! define_plan_node {
61
53
#[ allow( unused_mut, unused) ]
62
54
let mut data = None ;
63
55
$(
64
- data = Some ( $struct_name :: data_to_value ( & $ data_name) ) ;
56
+ data = Some ( $data_name. into ( ) ) ;
65
57
) *
66
58
$struct_name( $meta_typ(
67
59
optd_core:: rel_node:: RelNode {
@@ -103,9 +95,9 @@ macro_rules! define_plan_node {
103
95
// Dummy branch that does nothing when data is `None`.
104
96
( @expand_data_fields $self: ident, $struct_name: ident, $fields: ident) => { } ;
105
97
// Expand explain fields with data.
106
- ( @expand_data_fields $self: ident, $struct_name: ident, $fields: ident, $data_name : ident ) => {
98
+ ( @expand_data_fields $self: ident, $struct_name: ident, $fields: ident, $data_typ : ty ) => {
107
99
let value = $self. 0 . 0 . data. as_ref( ) . unwrap( ) ;
108
- $fields. extend( $struct_name:: explain_data( & $struct_name :: value_to_data ( & value) ) ) ;
100
+ $fields. extend( $struct_name:: explain_data( & value. into ( ) ) ) ;
109
101
} ;
110
102
}
111
103
@@ -141,28 +133,23 @@ mod test {
141
133
#[ derive( Clone , Debug ) ]
142
134
struct PhysicalComplexDummy ( PlanNode ) ;
143
135
144
- define_plan_node ! (
145
- PhysicalComplexDummy : PlanNode ,
146
- PhysicalScan , [
147
- { 0 , child: PlanNode }
148
- ] , [
149
- ] ,
150
- complex_data: ComplexData
151
- ) ;
152
-
153
- impl ExplainData < ComplexData > for PhysicalComplexDummy {
154
- fn data_to_value ( data : & ComplexData ) -> Value {
155
- Value :: Serialized ( bincode:: serialize ( data) . unwrap ( ) . into_iter ( ) . collect ( ) )
136
+ impl From < ComplexData > for Value {
137
+ fn from ( data : ComplexData ) -> Self {
138
+ Value :: Serialized ( bincode:: serialize ( & data) . unwrap ( ) . into_iter ( ) . collect ( ) )
156
139
}
140
+ }
157
141
158
- fn value_to_data ( value : & Value ) -> ComplexData {
142
+ impl From < & Value > for ComplexData {
143
+ fn from ( value : & Value ) -> Self {
159
144
if let Value :: Serialized ( serialized_data) = value {
160
145
bincode:: deserialize ( serialized_data) . unwrap ( )
161
146
} else {
162
147
unreachable ! ( )
163
148
}
164
149
}
150
+ }
165
151
152
+ impl ExplainData < ComplexData > for PhysicalComplexDummy {
166
153
fn explain_data ( data : & ComplexData ) -> Vec < ( & ' static str , Pretty < ' static > ) > {
167
154
vec ! [
168
155
( "a" , data. a. to_string( ) . into( ) ) ,
@@ -171,6 +158,15 @@ mod test {
171
158
}
172
159
}
173
160
161
+ define_plan_node ! (
162
+ PhysicalComplexDummy : PlanNode ,
163
+ PhysicalScan , [
164
+ { 0 , child: PlanNode }
165
+ ] , [
166
+ ] ,
167
+ complex_data: ComplexData
168
+ ) ;
169
+
174
170
let node = PhysicalComplexDummy :: new (
175
171
LogicalScan :: new ( "a" . to_string ( ) ) . 0 ,
176
172
ComplexData {
0 commit comments