@@ -32,14 +32,20 @@ use databend_common_expression::types::UInt64Type;
32
32
use databend_common_expression:: types:: VariantType ;
33
33
use databend_common_expression:: DataBlock ;
34
34
use databend_common_expression:: FromData ;
35
+ use databend_common_expression:: Scalar ;
36
+ use databend_common_functions:: BUILTIN_FUNCTIONS ;
35
37
use databend_common_meta_app:: schema:: TableIdent ;
36
38
use databend_common_meta_app:: schema:: TableInfo ;
37
39
use databend_common_meta_app:: schema:: TableMeta ;
38
40
use databend_common_sql:: plans:: task_schema;
39
41
use databend_common_users:: UserApiProvider ;
42
+ use databend_common_users:: BUILTIN_ROLE_ACCOUNT_ADMIN ;
43
+ use log:: info;
40
44
45
+ use crate :: parse_task_runs_to_datablock;
41
46
use crate :: table:: AsyncOneBlockSystemTable ;
42
47
use crate :: table:: AsyncSystemTable ;
48
+ use crate :: util:: find_eq_filter;
43
49
use crate :: util:: get_owned_task_names;
44
50
45
51
pub fn parse_tasks_to_datablock ( tasks : Vec < Task > ) -> Result < DataBlock > {
@@ -120,7 +126,7 @@ impl AsyncSystemTable for TasksTable {
120
126
async fn get_full_data (
121
127
& self ,
122
128
ctx : Arc < dyn TableContext > ,
123
- _push_downs : Option < PushDownInfo > ,
129
+ push_downs : Option < PushDownInfo > ,
124
130
) -> Result < DataBlock > {
125
131
let user_api = UserApiProvider :: instance ( ) ;
126
132
let config = GlobalConfig :: instance ( ) ;
@@ -140,7 +146,43 @@ impl AsyncSystemTable for TasksTable {
140
146
. map ( |x| x. identity ( ) . to_string ( ) )
141
147
. collect ( ) ;
142
148
149
+ let mut task_name = None ;
150
+ if let Some ( push_downs) = push_downs {
151
+ if let Some ( filter) = push_downs. filters . as_ref ( ) . map ( |f| & f. filter ) {
152
+ let expr = filter. as_expr ( & BUILTIN_FUNCTIONS ) ;
153
+ find_eq_filter ( & expr, & mut |col_name, scalar| {
154
+ if col_name == "name" {
155
+ if let Scalar :: String ( s) = scalar {
156
+ task_name = Some ( s. clone ( ) ) ;
157
+ }
158
+ }
159
+ } ) ;
160
+ }
161
+ }
143
162
let owned_tasks_names = get_owned_task_names ( user_api, & tenant, & all_effective_roles) . await ;
163
+ if let Some ( task_name) = & task_name {
164
+ // The user does not have admin role and not own the task_name
165
+ // Need directly return empty block
166
+ if !all_effective_roles
167
+ . iter ( )
168
+ . any ( |role| role. to_lowercase ( ) == BUILTIN_ROLE_ACCOUNT_ADMIN )
169
+ && !owned_tasks_names. contains ( task_name)
170
+ {
171
+ info ! (
172
+ "--tasks:171 all_effective_roles is {:?}, owned_tasks_names is {:?}, task_name is {:?}" ,
173
+ all_effective_roles. clone( ) ,
174
+ owned_tasks_names. clone( ) ,
175
+ task_name. clone( )
176
+ ) ;
177
+ return parse_task_runs_to_datablock ( vec ! [ ] ) ;
178
+ }
179
+ }
180
+ info ! (
181
+ "--tasks:175 all_effective_roles is {:?}, owned_tasks_names is {:?}, task_name is {:?}" ,
182
+ all_effective_roles. clone( ) ,
183
+ owned_tasks_names. clone( ) ,
184
+ task_name. clone( )
185
+ ) ;
144
186
145
187
let req = ShowTasksRequest {
146
188
tenant_id : tenant. tenant_name ( ) . to_string ( ) ,
0 commit comments