@@ -52,6 +52,8 @@ import org.apache.doris.common.Version;
52
52
import org.apache.doris.mysql.MysqlPassword;
53
53
import org.apache.doris.load.loadv2.LoadTask;
54
54
import org.apache.doris.policy.PolicyTypeEnum;
55
+ import org.apache.doris.resource.workloadschedpolicy.WorkloadConditionMeta;
56
+ import org.apache.doris.resource.workloadschedpolicy.WorkloadActionMeta;
55
57
56
58
import com.google.common.collect.Lists;
57
59
import com.google.common.collect.Maps;
@@ -530,6 +532,9 @@ terminal String
530
532
KW_PROCESSLIST,
531
533
KW_PROFILE,
532
534
KW_PROPERTIES,
535
+ KW_CONDITIONS,
536
+ KW_ACTIONS,
537
+ KW_SET_SESSION_VAR,
533
538
KW_PROPERTY,
534
539
KW_QUANTILE_STATE,
535
540
KW_QUANTILE_UNION,
@@ -841,6 +846,8 @@ nonterminal SetVar option_value, option_value_follow_option_type, option_value_n
841
846
// List of set variable
842
847
nonterminal List<SetVar> option_value_list, option_value_list_continued, start_option_value_list,
843
848
start_option_value_list_following_option_type, user_property_list;
849
+ nonterminal List<WorkloadConditionMeta> workload_policy_condition_list, conditions, opt_conditions;
850
+ nonterminal List<WorkloadActionMeta> workload_policy_action_list, opt_actions, actions;
844
851
845
852
nonterminal Map<String, String> key_value_map, opt_key_value_map, opt_key_value_map_in_paren, opt_properties,
846
853
opt_ext_properties, opt_enable_feature_properties, properties;
@@ -963,6 +970,9 @@ nonterminal StorageBackend storage_backend;
963
970
nonterminal ArrayList<LockTable> opt_lock_tables_list;
964
971
nonterminal LockTable lock_table;
965
972
973
+ // workload policy/group
974
+ nonterminal String policy_condition_op, policy_condition_value;
975
+
966
976
precedence nonassoc COMMA;
967
977
precedence nonassoc STRING_LITERAL;
968
978
precedence nonassoc KW_COLUMNS;
@@ -986,7 +996,7 @@ precedence left BITAND, BITOR, BITXOR;
986
996
precedence left KW_PIPE;
987
997
precedence left BITNOT;
988
998
precedence left KW_ORDER, KW_BY, KW_LIMIT;
989
- precedence right KW_PROPERTIES;
999
+ precedence right KW_PROPERTIES, KW_CONDITIONS, KW_ACTIONS ;
990
1000
precedence left LPAREN, RPAREN;
991
1001
precedence left KW_PREPARE, KW_EXECUTE;
992
1002
// Support chaining of timestamp arithmetic exprs.
@@ -1362,6 +1372,10 @@ alter_stmt ::=
1362
1372
{:
1363
1373
RESULT = new AlterWorkloadGroupStmt(workloadGroupName, properties);
1364
1374
:}
1375
+ | KW_ALTER KW_WORKLOAD KW_SCHEDULE KW_POLICY ident_or_text:policyName opt_properties:properties
1376
+ {:
1377
+ RESULT = new AlterWorkloadSchedPolicyStmt(policyName, properties);
1378
+ :}
1365
1379
| KW_ALTER KW_ROUTINE KW_LOAD KW_FOR job_label:jobLabel opt_properties:jobProperties
1366
1380
opt_datasource_properties:datasourceProperties
1367
1381
{:
@@ -1884,6 +1898,11 @@ create_stmt ::=
1884
1898
{:
1885
1899
RESULT = new CreateWorkloadGroupStmt(ifNotExists, workloadGroupName, properties);
1886
1900
:}
1901
+ /* workload schedule policy */
1902
+ | KW_CREATE KW_WORKLOAD KW_SCHEDULE KW_POLICY opt_if_not_exists:ifNotExists ident_or_text:workloadPolicyName opt_conditions:conditions opt_actions:actions opt_properties:properties
1903
+ {:
1904
+ RESULT = new CreateWorkloadSchedPolicyStmt(ifNotExists, workloadPolicyName, conditions, actions, properties);
1905
+ :}
1887
1906
/* encryptkey */
1888
1907
| KW_CREATE KW_ENCRYPTKEY opt_if_not_exists:ifNotExists encryptkey_name:keyName KW_AS STRING_LITERAL:keyString
1889
1908
{:
@@ -2987,6 +3006,10 @@ drop_stmt ::=
2987
3006
{:
2988
3007
RESULT = new DropWorkloadGroupStmt(ifExists, workloadGroupName);
2989
3008
:}
3009
+ | KW_DROP KW_WORKLOAD KW_SCHEDULE KW_POLICY opt_if_exists:ifExists ident_or_text:policyName
3010
+ {:
3011
+ RESULT = new DropWorkloadSchedPolicyStmt(ifExists, policyName);
3012
+ :}
2990
3013
| KW_DROP KW_ENCRYPTKEY opt_if_exists:ifExists encryptkey_name:keyName
2991
3014
{:
2992
3015
RESULT = new DropEncryptKeyStmt(ifExists, keyName);
@@ -3455,6 +3478,135 @@ opt_properties ::=
3455
3478
:}
3456
3479
;
3457
3480
3481
+ policy_condition_op ::=
3482
+ EQUAL
3483
+ {:
3484
+ RESULT = "=";
3485
+ :}
3486
+ | GREATERTHAN
3487
+ {:
3488
+ RESULT = ">";
3489
+ :}
3490
+ | LESSTHAN
3491
+ {:
3492
+ RESULT = "<";
3493
+ :}
3494
+ | GREATERTHAN EQUAL
3495
+ {:
3496
+ RESULT = ">=";
3497
+ :}
3498
+ | LESSTHAN EQUAL
3499
+ {:
3500
+ RESULT = "<=";
3501
+ :};
3502
+
3503
+ policy_condition_value ::=
3504
+ INTEGER_LITERAL:val
3505
+ {:
3506
+ RESULT = String.valueOf(val);
3507
+ :}
3508
+ | STRING_LITERAL:val
3509
+ {:
3510
+ RESULT = val;
3511
+ :}
3512
+ | FLOATINGPOINT_LITERAL:val
3513
+ {:
3514
+ RESULT = String.valueOf(val);
3515
+ :}
3516
+ | DECIMAL_LITERAL:val
3517
+ {:
3518
+ RESULT = val.toString();
3519
+ :}
3520
+ ;
3521
+
3522
+ workload_policy_condition_list ::=
3523
+ ident:metricName policy_condition_op:op policy_condition_value:value
3524
+ {:
3525
+ RESULT = new ArrayList<>();
3526
+ WorkloadConditionMeta cm = new WorkloadConditionMeta(metricName, op, value);
3527
+ RESULT.add(cm);
3528
+ :}
3529
+ | workload_policy_condition_list:list COMMA ident:metricName policy_condition_op:op policy_condition_value:value
3530
+ {:
3531
+ WorkloadConditionMeta cm = new WorkloadConditionMeta(metricName, op, value);
3532
+ list.add(cm);
3533
+ RESULT = list;
3534
+ :};
3535
+
3536
+ conditions ::=
3537
+ KW_CONDITIONS LPAREN workload_policy_condition_list:list RPAREN
3538
+ {:
3539
+ RESULT = list;
3540
+ :}
3541
+ ;
3542
+
3543
+ opt_conditions ::=
3544
+ {:
3545
+ RESULT = null;
3546
+ :}
3547
+ | conditions:conditions
3548
+ {:
3549
+ RESULT = conditions;
3550
+ :}
3551
+ ;
3552
+
3553
+ workload_policy_action_list ::=
3554
+ KW_SET_SESSION_VAR STRING_LITERAL:args
3555
+ {:
3556
+ RESULT = Lists.newArrayList();
3557
+ WorkloadActionMeta wam = new WorkloadActionMeta("set_session_variable", args);
3558
+ RESULT.add(wam);
3559
+ :}
3560
+ | workload_policy_action_list:list COMMA KW_SET_SESSION_VAR STRING_LITERAL:args
3561
+ {:
3562
+ WorkloadActionMeta wam = new WorkloadActionMeta("set_session_variable", args);
3563
+ list.add(wam);
3564
+ RESULT = list;
3565
+ :}
3566
+ | ident:firstArgs
3567
+ {:
3568
+ RESULT = Lists.newArrayList();
3569
+ WorkloadActionMeta wam = new WorkloadActionMeta(firstArgs, "");
3570
+ RESULT.add(wam);
3571
+ :}
3572
+ | ident:firstArgs STRING_LITERAL:secondArgs
3573
+ {:
3574
+ RESULT = Lists.newArrayList();
3575
+ WorkloadActionMeta wam = new WorkloadActionMeta(firstArgs, secondArgs);
3576
+ RESULT.add(wam);
3577
+ :}
3578
+ | workload_policy_action_list:list COMMA ident:firstArgs
3579
+ {:
3580
+ WorkloadActionMeta wam = new WorkloadActionMeta(firstArgs, "");
3581
+ list.add(wam);
3582
+ RESULT = list;
3583
+ :}
3584
+ | workload_policy_action_list:list COMMA ident:firstArgs STRING_LITERAL:secondArgs
3585
+ {:
3586
+ WorkloadActionMeta wam = new WorkloadActionMeta(firstArgs, secondArgs);
3587
+ list.add(wam);
3588
+ RESULT = list;
3589
+ :}
3590
+ ;
3591
+
3592
+
3593
+ actions ::=
3594
+ KW_ACTIONS LPAREN workload_policy_action_list:list RPAREN
3595
+ {:
3596
+ RESULT = list;
3597
+ :}
3598
+ ;
3599
+
3600
+ opt_actions ::=
3601
+ {:
3602
+ RESULT = null;
3603
+ :}
3604
+ | actions:actions
3605
+ {:
3606
+ RESULT = actions;
3607
+ :}
3608
+ ;
3609
+
3458
3610
opt_ext_properties ::=
3459
3611
{:
3460
3612
RESULT = null;
@@ -4003,6 +4155,10 @@ show_param ::=
4003
4155
{:
4004
4156
RESULT = new ShowWorkloadGroupsStmt();
4005
4157
:}
4158
+ | KW_WORKLOAD KW_SCHEDULE KW_POLICY
4159
+ {:
4160
+ RESULT = new ShowWorkloadSchedPolicyStmt();
4161
+ :}
4006
4162
| KW_BACKENDS
4007
4163
{:
4008
4164
RESULT = new ShowBackendsStmt();
@@ -7640,6 +7796,12 @@ keyword ::=
7640
7796
{: RESULT = id; :}
7641
7797
| KW_PROPERTIES:id
7642
7798
{: RESULT = id; :}
7799
+ | KW_CONDITIONS:id
7800
+ {: RESULT = id; :}
7801
+ | KW_ACTIONS:id
7802
+ {: RESULT = id; :}
7803
+ | KW_SET_SESSION_VAR:id
7804
+ {: RESULT = id; :}
7643
7805
| KW_PROPERTY:id
7644
7806
{: RESULT = id; :}
7645
7807
| KW_QUERY:id
0 commit comments