Skip to content

Commit

Permalink
[Feature](Job)Support Event Scheduler Job
Browse files Browse the repository at this point in the history
  • Loading branch information
CalvinKirs committed Jul 21, 2023
1 parent eb134d9 commit d26a6e6
Show file tree
Hide file tree
Showing 33 changed files with 1,038 additions and 454 deletions.
36 changes: 36 additions & 0 deletions Event.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
```sql
CREATE
[DEFINER = user]
EVENT
event_name
ON SCHEDULE schedule
[COMMENT 'string']
DO event_body;

schedule: {
AT timestamp
| EVERY interval
[STARTS timestamp ]
[ENDS timestamp ]
}

interval:
quantity { DAY | HOUR | MINUTE |
WEEK | SECOND }
```

eg:
```sql
CREATE
EVENT e_daily
ON SCHEDULE
EVERY 1 DAY
STARTS '2011-11-17 23:59:00'
ENDS '2038-01-19 03:14:07'
COMMENT 'Saves total number of sessions'
DO
INSERT INTO site_activity.totals (time, total)
SELECT CURRENT_TIMESTAMP, COUNT(*)
FROM site_activity.sessions;

```
23 changes: 13 additions & 10 deletions fe/fe-core/src/main/cup/sql_parser.cup
Original file line number Diff line number Diff line change
Expand Up @@ -2632,15 +2632,14 @@ resource_desc ::=
:}
;
create_event_stmt ::=
KW_CREATE KW_EVENT job_label:jobLabel KW_ON KW_SCHEDULER KW_EVERY KW_INTERVAL INTEGER_LITERAL:time_interval ident:time_unit opt_event_starts:startsTime opt_event_ends:endsTime event_do:executeSql opt_comment:comment

KW_CREATE KW_EVENT job_label:jobLabel KW_ON KW_SCHEDULER KW_EVERY INTEGER_LITERAL:time_interval ident:time_unit opt_event_starts:startsTime opt_event_ends:endsTime opt_comment:comment KW_DO stmt:executeSql
{:
CreateJobStmt stmt = new CreateJobStmt();
CreateJobStmt stmt = new CreateJobStmt(jobLabel,null,time_interval,time_unit, startsTime, endsTime,comment,executeSql);
RESULT = stmt;
:}
| KW_CREATE KW_EVENT job_label:jobLabel KW_ON KW_SCHEDULER KW_AT STRING_LITERAL:at_time event_do:executeSql opt_comment:comment
| KW_CREATE KW_EVENT job_label:jobLabel KW_ON KW_SCHEDULER KW_AT STRING_LITERAL:atTime opt_comment:comment KW_DO stmt:executeSql
{:
CreateJobStmt stmt = new CreateJobStmt();
CreateJobStmt stmt = new CreateJobStmt(jobLabel,atTime,null,null,null,null,comment,executeSql);
RESULT = stmt;
:}
;
Expand Down Expand Up @@ -2672,24 +2671,28 @@ create_event_stmt ::=
resume_event_stmt ::=
KW_RESUME KW_EVENT job_label:jobLabel
{:
RESULT = new ResumeJobStmt();
RESULT = new ResumeJobStmt(jobLabel);
:}
;
show_event_stmt ::=
KW_SHOW KW_SCHEDULER KW_JOB KW_FOR job_label:jobLabel
KW_SHOW KW_EVENT
{:
RESULT = new ShowRoutineLoadStmt(jobLabel, false, null);
RESULT = new ShowJobStmt(null,null);
:}
| KW_SHOW KW_EVENT KW_FOR job_label:jobLabel
{:
RESULT = new ShowJobStmt(jobLabel,null);
:}
;
pause_event_stmt ::=
KW_PAUSE KW_STARTS KW_JOB KW_FOR job_label:jobLabel
KW_PAUSE KW_EVENT KW_FOR job_label:jobLabel
{:
RESULT = new PauseJobStmt(jobLabel);
:}
;

stop_event_stmt ::=
KW_STOP KW_EVENT job_label:jobLabel
KW_STOP KW_EVENT KW_FOR job_label:jobLabel
{:
RESULT = new StopJobStmt(jobLabel);
:}
Expand Down
Loading

0 comments on commit d26a6e6

Please sign in to comment.