From 39c2b956ebd628b47c50016ac35bfaef52d123ef Mon Sep 17 00:00:00 2001 From: Jenny V Medina Date: Fri, 13 Dec 2024 16:13:44 -0500 Subject: [PATCH] [SNOW-175] `node_latest` dynamic table query update: Add stricter filter to remove deleted nodes (#93) --- ....26.5__remove_ghost_assets_node_latest.sql | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 synapse_data_warehouse/synapse/dynamic_tables/V2.26.5__remove_ghost_assets_node_latest.sql diff --git a/synapse_data_warehouse/synapse/dynamic_tables/V2.26.5__remove_ghost_assets_node_latest.sql b/synapse_data_warehouse/synapse/dynamic_tables/V2.26.5__remove_ghost_assets_node_latest.sql new file mode 100644 index 00000000..fa038c59 --- /dev/null +++ b/synapse_data_warehouse/synapse/dynamic_tables/V2.26.5__remove_ghost_assets_node_latest.sql @@ -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;