Skip to content

Commit

Permalink
Merge pull request #82 from Sage-Bionetworks/snow-27-add-usergroup-la…
Browse files Browse the repository at this point in the history
…test

[SNOW-27] add version script to populate usergroup_latest table
  • Loading branch information
danlu1 authored Nov 15, 2024
2 parents 6555b15 + 8edfab9 commit d06228f
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use schema {{database_name}}.synapse; --noqa: JJ01,PRS,TMP,CP01

CREATE OR REPLACE DYNAMIC TABLE USERGROUP_LATEST
TARGET_LAG = '1 day'
WAREHOUSE = compute_xsmall
AS
WITH dedup_usergroup AS (
SELECT
*,
"row_number"()
OVER (
PARTITION BY ID
ORDER BY CHANGE_TIMESTAMP DESC, SNAPSHOT_TIMESTAMP DESC
)
AS N
FROM {{database_name}}.SYNAPSE_RAW.USERGROUPSNAPSHOTS --noqa: TMP
WHERE
SNAPSHOT_TIMESTAMP >= CURRENT_TIMESTAMP - INTERVAL '14 days'
QUALIFY
N=1
)
SELECT * EXCLUDE N
FROM dedup_usergroup;

0 comments on commit d06228f

Please sign in to comment.