forked from sqlfluff/sqlfluff
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Snowflake: Add implementation for CREATE TASK statement (sqlfluff#1597)
- Loading branch information
Joe Hutter
committed
Oct 12, 2021
1 parent
c61003a
commit 66421a9
Showing
3 changed files
with
623 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
test/fixtures/dialects/snowflake/snowflake_create_task.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
-- Examples from the documentation | ||
|
||
CREATE TASK t1 | ||
SCHEDULE = 'USING CRON 0 9-17 * * SUN America/Los_Angeles' | ||
TIMESTAMP_INPUT_FORMAT = 'YYYY-MM-DD HH24' | ||
USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE = 'XSMALL' | ||
AS | ||
INSERT INTO mytable(ts) VALUES(1); | ||
|
||
CREATE TASK mytask_hour | ||
WAREHOUSE = mywh | ||
SCHEDULE = 'USING CRON 0 9-17 * * SUN America/Los_Angeles' | ||
TIMESTAMP_INPUT_FORMAT = 'YYYY-MM-DD HH24' | ||
AS | ||
INSERT INTO mytable(ts) VALUES(1, 2, 3); | ||
|
||
-- All possible optional clauses | ||
CREATE OR REPLACE TASK IF NOT EXISTS t1 | ||
WAREHOUSE = mywh | ||
SCHEDULE = 'USING CRON 0 9-17 * * SUN America/Los_Angeles' | ||
ALLOW_OVERLAPPING_EXECUTION = TRUE | ||
TIMESTAMP_INPUT_FORMAT = 'YYYY-MM-DD HH24' | ||
USER_TASK_TIMEOUT_MS = 25 | ||
USER_TASK_MANAGED_INITIAL_WAREHOUSE_SIZE = 'XSMALL' | ||
COPY GRANTS | ||
COMMENT = 'Hello world' | ||
AFTER dependency_task | ||
AS | ||
INSERT INTO mytable(ts) VALUES(1); | ||
|
||
-- Only mandatory clauses | ||
CREATE TASK t1 | ||
AS | ||
INSERT INTO mytable(ts) VALUES(1); | ||
|
||
-- Real life examples | ||
CREATE OR REPLACE TASK insert_session | ||
WAREHOUSE = eng_wh | ||
SCHEDULE = 'USING CRON 45 6 * * * UTC' | ||
AS | ||
INSERT INTO sch.s_session | ||
SELECT | ||
*, | ||
sum(break) OVER (PARTITION BY serial ORDER BY datetime) AS session_id | ||
FROM | ||
( | ||
SELECT * | ||
FROM base_table | ||
) | ||
; | ||
|
||
|
||
CREATE OR REPLACE TASK update_session | ||
WAREHOUSE = eng_wh | ||
AFTER insert_session | ||
AS | ||
UPDATE sch.s_session | ||
SET lag_datetime = v.lag_datetime, row_number = v.row_number | ||
FROM | ||
( | ||
SELECT | ||
*, | ||
( | ||
sum(break) OVER (PARTITION BY serial ORDER BY datetime) | ||
) AS session_id | ||
FROM | ||
( | ||
SELECT * | ||
FROM derived_table | ||
) | ||
ORDER BY serial, datetime | ||
) AS v | ||
WHERE sch.s_session.event_id = v.event_id | ||
; | ||
|
||
CREATE OR REPLACE TASK sch.truncate_session | ||
WAREHOUSE = eng_wh | ||
AFTER sch.update_session | ||
AS | ||
CALL sch.session_agg_insert(); | ||
|
||
CREATE OR REPLACE TASK insert__agg | ||
WAREHOUSE = eng_wh | ||
SCHEDULE = 'USING CRON 15 7 2 * * UTC' | ||
AS | ||
CALL auto_device_insert(); |
Oops, something went wrong.