Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasyu888 committed May 13, 2024
1 parent 5035db4 commit ae4cb09
Showing 1 changed file with 70 additions and 0 deletions.
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');

0 comments on commit ae4cb09

Please sign in to comment.