Skip to content

Commit

Permalink
[SNOW-175] Convert node_latest table -> dynamic table (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymedina authored Dec 12, 2024
1 parent c0523e1 commit 6cfeb86
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
USE SCHEMA {{database_name}}.synapse; --noqa: JJ01,PRS,TMP

CREATE DYNAMIC TABLE IF NOT EXISTS NODE_LATEST
TARGET_LAG = '1 day'
WAREHOUSE = compute_xsmall
AS
WITH latest_unique_rows AS (
SELECT
*
FROM
{{database_name}}.synapse_raw.nodesnapshots --noqa: TMP
WHERE
SNAPSHOT_TIMESTAMP >= CURRENT_TIMESTAMP - INTERVAL '14 DAYS'
QUALIFY ROW_NUMBER() OVER (
PARTITION BY id
ORDER BY change_timestamp DESC, snapshot_timestamp DESC
) = 1
)
SELECT
*
FROM
latest_unique_rows
WHERE
CHANGE_TYPE != 'DELETE'
ORDER BY
latest_unique_rows.id ASC;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
USE SCHEMA {{database_name}}.synapse; --noqa: JJ01,PRS,TMP

-- Clone the NODE_LATEST table to ``NODE_LATEST_BACKUP``
-- This will begin the process of converting ``NODE_LATEST`` table into a dynamic table
CREATE OR REPLACE TABLE NODE_LATEST_BACKUP CLONE NODE_LATEST;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
USE SCHEMA {{database_name}}.synapse; --noqa: JJ01,PRS,TMP

-- Drop the ``NODE_LATEST`` table so that a new dynamic table with the same name can be created in its place
DROP TABLE NODE_LATEST;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
USE SCHEMA {{database_name}}.synapse_raw; --noqa: JJ01,PRS,TMP

DROP STREAM IF EXISTS NODESNAPSHOTS_STREAM;
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
USE SCHEMA {{database_name}}.synapse_raw; --noqa: JJ01,PRS,TMP

-- Momentarily suspend the ROOT task so we can remove the child tasks
ALTER TASK IF EXISTS REFRESH_SYNAPSE_WAREHOUSE_S3_STAGE_TASK SUSPEND;

-- Remove the tasks in question
DROP TASK IF EXISTS UPSERT_TO_NODE_LATEST_TASK;
DROP TASK IF EXISTS REMOVE_DELETE_NODES_TASK;

-- Resume the ROOT task and its child tasks
SELECT SYSTEM$TASK_DEPENDENTS_ENABLE( 'REFRESH_SYNAPSE_WAREHOUSE_S3_STAGE_TASK' );

0 comments on commit 6cfeb86

Please sign in to comment.