@@ -32,13 +32,13 @@ use databend_common_pipeline_sources::AsyncSource;
32
32
use databend_common_pipeline_sources:: AsyncSourcer ;
33
33
34
34
pub struct RuntimeFilterSourceProcessor {
35
- pub meta_receiver : Receiver < RuntimeFilterMeta > ,
35
+ pub meta_receiver : Receiver < RuntimeFiltersMeta > ,
36
36
}
37
37
38
38
impl RuntimeFilterSourceProcessor {
39
39
pub fn create (
40
40
ctx : Arc < dyn TableContext > ,
41
- receiver : Receiver < RuntimeFilterMeta > ,
41
+ receiver : Receiver < RuntimeFiltersMeta > ,
42
42
output_port : Arc < OutputPort > ,
43
43
) -> Result < ProcessorPtr > {
44
44
AsyncSourcer :: create ( ctx, output_port, Self {
@@ -63,12 +63,7 @@ impl AsyncSource for RuntimeFilterSourceProcessor {
63
63
rf. is_ok( )
64
64
) ;
65
65
match rf {
66
- Ok ( runtime_filter) => Ok ( Some ( DataBlock :: empty_with_meta ( Box :: new (
67
- RuntimeFilterMeta {
68
- inlist : runtime_filter. inlist ,
69
- min_max : runtime_filter. min_max ,
70
- } ,
71
- ) ) ) ) ,
66
+ Ok ( runtime_filter) => Ok ( Some ( DataBlock :: empty_with_meta ( Box :: new ( runtime_filter) ) ) ) ,
72
67
Err ( _) => {
73
68
// The channel is closed, we should return None to stop generating
74
69
Ok ( None )
@@ -77,22 +72,29 @@ impl AsyncSource for RuntimeFilterSourceProcessor {
77
72
}
78
73
}
79
74
75
+ #[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize , Default ) ]
76
+ pub struct RuntimeFiltersMeta {
77
+ runtime_filters : Vec < RuntimeFilterMeta > ,
78
+ }
79
+
80
80
#[ derive( Debug , Clone , serde:: Serialize , serde:: Deserialize ) ]
81
81
pub struct RuntimeFilterMeta {
82
+ scan_id : usize ,
82
83
inlist : Vec < RemoteExpr < String > > ,
83
84
min_max : Vec < RemoteExpr < String > > ,
84
85
}
85
86
86
- #[ typetag:: serde( name = "runtime_filter_meta " ) ]
87
- impl BlockMetaInfo for RuntimeFilterMeta {
87
+ #[ typetag:: serde( name = "runtime_filters_meta " ) ]
88
+ impl BlockMetaInfo for RuntimeFiltersMeta {
88
89
fn clone_self ( & self ) -> Box < dyn BlockMetaInfo > {
89
90
Box :: new ( self . clone ( ) )
90
91
}
91
92
}
92
93
93
- impl From < & RuntimeFilterInfo > for RuntimeFilterMeta {
94
- fn from ( runtime_filter_info : & RuntimeFilterInfo ) -> Self {
95
- Self {
94
+ impl RuntimeFiltersMeta {
95
+ pub fn add ( & mut self , scan_id : usize , runtime_filter_info : & RuntimeFilterInfo ) {
96
+ let rf = RuntimeFilterMeta {
97
+ scan_id,
96
98
inlist : runtime_filter_info
97
99
. inlists_ref ( )
98
100
. iter ( )
@@ -103,14 +105,21 @@ impl From<&RuntimeFilterInfo> for RuntimeFilterMeta {
103
105
. iter ( )
104
106
. map ( |expr| expr. as_remote_expr ( ) )
105
107
. collect ( ) ,
106
- }
108
+ } ;
109
+ self . runtime_filters . push ( rf) ;
107
110
}
108
111
}
109
- pub struct RuntimeFilterSinkProcessor { }
112
+ pub struct RuntimeFilterSinkProcessor {
113
+ node_num : usize ,
114
+ recv_num : usize ,
115
+ }
110
116
111
117
impl RuntimeFilterSinkProcessor {
112
- pub fn create ( input : Arc < InputPort > ) -> Result < ProcessorPtr > {
113
- Ok ( ProcessorPtr :: create ( AsyncSinker :: create ( input, Self { } ) ) )
118
+ pub fn create ( input : Arc < InputPort > , node_num : usize ) -> Result < ProcessorPtr > {
119
+ Ok ( ProcessorPtr :: create ( AsyncSinker :: create ( input, Self {
120
+ node_num,
121
+ recv_num : 0 ,
122
+ } ) ) )
114
123
}
115
124
}
116
125
@@ -128,12 +137,13 @@ impl AsyncSink for RuntimeFilterSinkProcessor {
128
137
let ptr = data_block
129
138
. take_meta ( )
130
139
. ok_or_else ( || ErrorCode :: Internal ( "Cannot downcast meta to RuntimeFilterMeta" ) ) ?;
131
- let runtime_filter = RuntimeFilterMeta :: downcast_from ( ptr)
140
+ let runtime_filter = RuntimeFiltersMeta :: downcast_from ( ptr)
132
141
. ok_or_else ( || ErrorCode :: Internal ( "Cannot downcast meta to RuntimeFilterMeta" ) ) ?;
133
142
log:: info!(
134
143
"RuntimeFilterSinkProcessor recv runtime filter: {:?}" ,
135
144
runtime_filter
136
145
) ;
137
- Ok ( true )
146
+ self . recv_num += 1 ;
147
+ Ok ( self . node_num == self . recv_num )
138
148
}
139
149
}
0 commit comments