Skip to content

Commit

Permalink
[SNOW-175] node_latest dynamic table query update: Add stricter fil…
Browse files Browse the repository at this point in the history
…ter to remove deleted nodes (#93)
  • Loading branch information
jaymedina authored Dec 13, 2024
1 parent 6cfeb86 commit 39c2b95
Showing 1 changed file with 26 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 OR REPLACE DYNAMIC TABLE 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 '30 DAYS'
QUALIFY ROW_NUMBER() OVER (
PARTITION BY id
ORDER BY change_timestamp DESC, snapshot_timestamp DESC
) = 1
)
SELECT
*
FROM
latest_unique_rows
WHERE
NOT (CHANGE_TYPE = 'DELETE' OR BENEFACTOR_ID = '1681355' OR PARENT_ID = '1681355') -- 1681355 is the synID of the trash can on Synapse
ORDER BY
latest_unique_rows.id ASC;

0 comments on commit 39c2b95

Please sign in to comment.