-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5035db4
commit ae4cb09
Showing
1 changed file
with
70 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
synapse_data_warehouse/synapse_raw/tasks/V2.16.4__fix_cert_typo.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,70 @@ | ||
USE ROLE accountadmin; | ||
use schema {{database_name}}.synapse_raw; --noqa: JJ01,PRS,TMP,CP01 | ||
ALTER TASK refresh_synapse_warehouse_s3_stage_task SUSPEND; | ||
ALTER TASK APPEND_TO_CERTIFIEDQUIZSNAPSHOT_TASK SUSPEND; | ||
ALTER TASK UPSERT_TO_CERTIFIEDQUIZ_LATEST_TASK SUSPEND; | ||
alter task UPSERT_TO_CERTIFIEDQUIZ_LATEST_TASK MODIFY AS | ||
MERGE INTO {{database_name}}.SYNAPSE.CERTIFIEDQUIZ_LATEST AS TARGET_TABLE --noqa: TMP | ||
USING ( | ||
WITH CQQ_RANKED AS ( | ||
SELECT | ||
*, | ||
ROW_NUMBER() OVER ( | ||
PARTITION BY USER_ID | ||
ORDER BY INSTANCE DESC, RESPONSE_ID DESC | ||
) AS ROW_NUM | ||
FROM CERTIFIEDQUIZ_STREAM | ||
) | ||
|
||
SELECT * EXCLUDE ROW_NUM | ||
FROM CQQ_RANKED | ||
WHERE ROW_NUM = 1 | ||
) AS SOURCE_TABLE ON TARGET_TABLE.USER_ID = SOURCE_TABLE.USER_ID | ||
WHEN MATCHED THEN | ||
UPDATE SET | ||
TARGET_TABLE.CHANGE_TYPE = SOURCE_TABLE.CHANGE_TYPE, | ||
TARGET_TABLE.CHANGE_TIMESTAMP = SOURCE_TABLE.CHANGE_TIMESTAMP, | ||
TARGET_TABLE.SNAPSHOT_TIMESTAMP = SOURCE_TABLE.SNAPSHOT_TIMESTAMP, | ||
TARGET_TABLE.RESPONSE_ID = SOURCE_TABLE.RESPONSE_ID, | ||
TARGET_TABLE.PASSED = SOURCE_TABLE.PASSED, | ||
TARGET_TABLE.PASSED_ON = SOURCE_TABLE.PASSED_ON, | ||
TARGET_TABLE.STACK = SOURCE_TABLE.STACK, | ||
TARGET_TABLE.INSTANCE = SOURCE_TABLE.INSTANCE, | ||
TARGET_TABLE.SNAPSHOT_DATE = SOURCE_TABLE.SNAPSHOT_DATE, | ||
TARGET_TABLE.REVOKED = SOURCE_TABLE.REVOKED, | ||
TARGET_TABLE.REVOKED_ON = SOURCE_TABLE.REVOKED_ON, | ||
TARGET_TABLE.CERTIFIED = SOURCE_TABLE.CERTIFIED | ||
WHEN NOT MATCHED THEN | ||
INSERT ( | ||
CHANGE_TYPE, | ||
CHANGE_TIMESTAMP, | ||
SNAPSHOT_TIMESTAMP, | ||
RESPONSE_ID, | ||
USER_ID, | ||
PASSED, | ||
PASSED_ON, | ||
STACK, | ||
INSTANCE, | ||
SNAPSHOT_DATE, | ||
REVOKED, | ||
REVOKED_ON, | ||
CERTIFIED | ||
) | ||
VALUES ( | ||
SOURCE_TABLE.CHANGE_TYPE, | ||
SOURCE_TABLE.CHANGE_TIMESTAMP, | ||
SOURCE_TABLE.SNAPSHOT_TIMESTAMP, | ||
SOURCE_TABLE.RESPONSE_ID, | ||
SOURCE_TABLE.USER_ID, | ||
SOURCE_TABLE.PASSED, | ||
SOURCE_TABLE.PASSED_ON, | ||
SOURCE_TABLE.STACK, | ||
SOURCE_TABLE.INSTANCE, | ||
SOURCE_TABLE.SNAPSHOT_DATE, | ||
SOURCE_TABLE.REVOKED, | ||
SOURCE_TABLE.REVOKED_ON, | ||
SOURCE_TABLE.CERTIFIED | ||
); | ||
|
||
// https://docs.snowflake.com/en/sql-reference/functions/system_task_dependents_enable | ||
SELECT SYSTEM$TASK_DEPENDENTS_ENABLE('refresh_synapse_warehouse_s3_stage_task'); |